parameters: (df, q)
return_statement: return df
docstring: Approximate quantiles of DataFrame or Series.
      [NOTE: Same logic as dask.dataframe Series quantile]
docstring_summary: Approximate quantiles of DataFrame or Series.
      [NOTE: Same logic as dask.dataframe Series quantile]
docstring_tokens: Approximate quantiles of DataFrame or Series . [ NOTE : Same logic as dask . dataframe Series quantile ]
function: def _approximate_quantile(df, q):
      """Approximate quantiles of DataFrame or Series.
      [NOTE: Same logic as dask.dataframe Series quantile]
      """
      # current implementation needs q to be sorted so
      # sort if array-like, otherwise leave it alone
      q_ndarray = np.array(q)
      if q_ndarray.ndim > 0:
          q_ndarray.sort(kind="mergesort")
          q = q_ndarray
  
      # Lets assume we are dealing with a DataFrame throughout
      if isinstance(df, (Series, Index)):
          df = df.to_frame()
      assert isinstance(df, DataFrame)
      final_type = df._meta._constructor
  
      # Create metadata
      meta = df._meta_nonempty.quantiles(q=q)
  
      # Define final action (create df with quantiles as index)
      def finalize_tsk(tsk):
          return (final_type, tsk)
  
      return_type = df.__class__
  
      # pandas/cudf uses quantile in [0, 1]
      # numpy / cupy uses [0, 100]
      qs = np.asarray(q)
      token = tokenize(df, qs)
  
      if len(qs) == 0:
          name = "quantiles-" + token
          empty_index = gd.Index([], dtype=float)
          return Series(
              {
                  (name, 0): final_type(
                      {col: [] for col in df.columns},
                      name=df.name,
                      index=empty_index,
                  )
              },
              name,
              df._meta,
              [None, None],
          )
      else:
          new_divisions = [np.min(q), np.max(q)]
  
      name = "quantiles-1-" + token
      val_dsk = {
          (name, i): (_quantile, key, qs)
          for i, key in enumerate(df.__dask_keys__())
      }
  
      name2 = "quantiles-2-" + token
      merge_dsk = {
          (name2, 0): finalize_tsk(
              (merge_quantiles, qs, [qs] * df.npartitions, sorted(val_dsk))
          )
      }
      dsk = toolz.merge(val_dsk, merge_dsk)
      graph = HighLevelGraph.from_collections(name2, dsk, dependencies=[df])
      df = return_type(graph, name2, meta, new_divisions)
  
      def set_quantile_index(df):
          df.index = q
          return df
  
      df = df.map_partitions(set_quantile_index, meta=meta)
      return df
function_tokens: def _approximate_quantile ( df , q ) : # current implementation needs q to be sorted so # sort if array-like, otherwise leave it alone q_ndarray = np . array ( q ) if q_ndarray . ndim > 0 : q_ndarray . sort ( kind = "mergesort" ) q = q_ndarray # Lets assume we are dealing with a DataFrame throughout if isinstance ( df , ( Series , Index ) ) : df = df . to_frame ( ) assert isinstance ( df , DataFrame ) final_type = df . _meta . _constructor # Create metadata meta = df . _meta_nonempty . quantiles ( q = q ) # Define final action (create df with quantiles as index) def finalize_tsk ( tsk ) : return ( final_type , tsk ) return_type = df . __class__ # pandas/cudf uses quantile in [0, 1] # numpy / cupy uses [0, 100] qs = np . asarray ( q ) token = tokenize ( df , qs ) if len ( qs ) == 0 : name = "quantiles-" + token empty_index = gd . Index ( [ ] , dtype = float ) return Series ( { ( name , 0 ) : final_type ( { col : [ ] for col in df . columns } , name = df . name , index = empty_index , ) } , name , df . _meta , [ None , None ] , ) else : new_divisions = [ np . min ( q ) , np . max ( q ) ] name = "quantiles-1-" + token val_dsk = { ( name , i ) : ( _quantile , key , qs ) for i , key in enumerate ( df . __dask_keys__ ( ) ) } name2 = "quantiles-2-" + token merge_dsk = { ( name2 , 0 ) : finalize_tsk ( ( merge_quantiles , qs , [ qs ] * df . npartitions , sorted ( val_dsk ) ) ) } dsk = toolz . merge ( val_dsk , merge_dsk ) graph = HighLevelGraph . from_collections ( name2 , dsk , dependencies = [ df ] ) df = return_type ( graph , name2 , meta , new_divisions ) def set_quantile_index ( df ) : df . index = q return df df = df . map_partitions ( set_quantile_index , meta = meta ) return df