parameters: (self, q=0.5, interpolation: str = "linear")
docstring: Return group values at the given quantile, a la numpy.percentile.
  
          Parameters
          ----------
          q : float or array-like, default 0.5 (50% quantile)
              Value(s) between 0 and 1 providing the quantile(s) to compute.
          interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
              Method to use when the desired quantile falls between two points.
  
          Returns
          -------
          Series or DataFrame
              Return type determined by caller of GroupBy object.
  
          See Also
          --------
          Series.quantile : Similar method for Series.
          DataFrame.quantile : Similar method for DataFrame.
          numpy.percentile : NumPy method to compute qth percentile.
  
          Examples
          --------
          >>> df = pd.DataFrame([
          ...     ['a', 1], ['a', 2], ['a', 3],
          ...     ['b', 1], ['b', 3], ['b', 5]
          ... ], columns=['key', 'val'])
          >>> df.groupby('key').quantile()
              val
          key
          a    2.0
          b    3.0
docstring_summary: Return group values at the given quantile, a la numpy.percentile.
docstring_tokens: Return group values at the given quantile a la numpy . percentile .
function: def quantile(self, q=0.5, interpolation: str = "linear"):
          """
          Return group values at the given quantile, a la numpy.percentile.
  
          Parameters
          ----------
          q : float or array-like, default 0.5 (50% quantile)
              Value(s) between 0 and 1 providing the quantile(s) to compute.
          interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
              Method to use when the desired quantile falls between two points.
  
          Returns
          -------
          Series or DataFrame
              Return type determined by caller of GroupBy object.
  
          See Also
          --------
          Series.quantile : Similar method for Series.
          DataFrame.quantile : Similar method for DataFrame.
          numpy.percentile : NumPy method to compute qth percentile.
  
          Examples
          --------
          >>> df = pd.DataFrame([
          ...     ['a', 1], ['a', 2], ['a', 3],
          ...     ['b', 1], ['b', 3], ['b', 5]
          ... ], columns=['key', 'val'])
          >>> df.groupby('key').quantile()
              val
          key
          a    2.0
          b    3.0
          """
          from pandas import concat
  
          def pre_processor(vals: ArrayLike) -> tuple[np.ndarray, np.dtype | None]:
              if is_object_dtype(vals):
                  raise TypeError(
                      "'quantile' cannot be performed against 'object' dtypes!"
                  )
  
              inference: np.dtype | None = None
              if is_integer_dtype(vals.dtype):
                  if isinstance(vals, ExtensionArray):
                      out = vals.to_numpy(dtype=float, na_value=np.nan)
                  else:
                      out = vals
                  inference = np.dtype(np.int64)
              elif is_bool_dtype(vals.dtype) and isinstance(vals, ExtensionArray):
                  out = vals.to_numpy(dtype=float, na_value=np.nan)
              elif is_datetime64_dtype(vals.dtype):
                  inference = np.dtype("datetime64[ns]")
                  out = np.asarray(vals).astype(float)
              elif is_timedelta64_dtype(vals.dtype):
                  inference = np.dtype("timedelta64[ns]")
                  out = np.asarray(vals).astype(float)
              elif isinstance(vals, ExtensionArray) and is_float_dtype(vals):
                  inference = np.dtype(np.float64)
                  out = vals.to_numpy(dtype=float, na_value=np.nan)
              else:
                  out = np.asarray(vals)
  
              return out, inference
  
          def post_processor(vals: np.ndarray, inference: type | None) -> np.ndarray:
              if inference:
                  # Check for edge case
                  if not (
                      is_integer_dtype(inference)
                      and interpolation in {"linear", "midpoint"}
                  ):
                      vals = vals.astype(inference)
  
              return vals
  
          if is_scalar(q):
              return self._get_cythonized_result(
                  "group_quantile",
                  aggregate=True,
                  numeric_only=False,
                  needs_values=True,
                  needs_mask=True,
                  cython_dtype=np.dtype(np.float64),
                  pre_processing=pre_processor,
                  post_processing=post_processor,
                  q=q,
                  interpolation=interpolation,
              )
          else:
              results = [
                  self._get_cythonized_result(
                      "group_quantile",
                      aggregate=True,
                      needs_values=True,
                      needs_mask=True,
                      cython_dtype=np.dtype(np.float64),
                      pre_processing=pre_processor,
                      post_processing=post_processor,
                      q=qi,
                      interpolation=interpolation,
                  )
                  for qi in q
              ]
              result = concat(results, axis=self.axis, keys=q)
              # fix levels to place quantiles on the inside
              # TODO(GH-10710): Ideally, we could write this as
              #  >>> result.stack(0).loc[pd.IndexSlice[:, ..., q], :]
              #  but this hits https://github.com/pandas-dev/pandas/issues/10710
              #  which doesn't reorder the list-like `q` on the inner level.
              order = list(range(1, result.axes[self.axis].nlevels)) + [0]
  
              # temporarily saves the index names
              index_names = np.array(result.axes[self.axis].names)
  
              # set index names to positions to avoid confusion
              result.axes[self.axis].names = np.arange(len(index_names))
  
              # place quantiles on the inside
              if isinstance(result, Series):
                  result = result.reorder_levels(order)
              else:
                  result = result.reorder_levels(order, axis=self.axis)
  
              # restore the index names in order
              result.axes[self.axis].names = index_names[order]
  
              # reorder rows to keep things sorted
              indices = (
                  np.arange(result.shape[self.axis])
                  .reshape([len(q), self.ngroups])
                  .T.flatten()
              )
              return result.take(indices, axis=self.axis)
function_tokens: def quantile ( self , q = 0.5 , interpolation : str = "linear" ) : from pandas import concat def pre_processor ( vals : ArrayLike ) -> tuple [ np . ndarray , np . dtype | None ] : if is_object_dtype ( vals ) : raise TypeError ( "'quantile' cannot be performed against 'object' dtypes!" ) inference : np . dtype | None = None if is_integer_dtype ( vals . dtype ) : if isinstance ( vals , ExtensionArray ) : out = vals . to_numpy ( dtype = float , na_value = np . nan ) else : out = vals inference = np . dtype ( np . int64 ) elif is_bool_dtype ( vals . dtype ) and isinstance ( vals , ExtensionArray ) : out = vals . to_numpy ( dtype = float , na_value = np . nan ) elif is_datetime64_dtype ( vals . dtype ) : inference = np . dtype ( "datetime64[ns]" ) out = np . asarray ( vals ) . astype ( float ) elif is_timedelta64_dtype ( vals . dtype ) : inference = np . dtype ( "timedelta64[ns]" ) out = np . asarray ( vals ) . astype ( float ) elif isinstance ( vals , ExtensionArray ) and is_float_dtype ( vals ) : inference = np . dtype ( np . float64 ) out = vals . to_numpy ( dtype = float , na_value = np . nan ) else : out = np . asarray ( vals ) return out , inference def post_processor ( vals : np . ndarray , inference : type | None ) -> np . ndarray : if inference : # Check for edge case if not ( is_integer_dtype ( inference ) and interpolation in { "linear" , "midpoint" } ) : vals = vals . astype ( inference ) return vals if is_scalar ( q ) : return self . _get_cythonized_result ( "group_quantile" , aggregate = True , numeric_only = False , needs_values = True , needs_mask = True , cython_dtype = np . dtype ( np . float64 ) , pre_processing = pre_processor , post_processing = post_processor , q = q , interpolation = interpolation , ) else : results = [ self . _get_cythonized_result ( "group_quantile" , aggregate = True , needs_values = True , needs_mask = True , cython_dtype = np . dtype ( np . float64 ) , pre_processing = pre_processor , post_processing = post_processor , q = qi , interpolation = interpolation , ) for qi in q ] result = concat ( results , axis = self . axis , keys = q ) # fix levels to place quantiles on the inside # TODO(GH-10710): Ideally, we could write this as #  >>> result.stack(0).loc[pd.IndexSlice[:, ..., q], :] #  but this hits https://github.com/pandas-dev/pandas/issues/10710 #  which doesn't reorder the list-like `q` on the inner level. order = list ( range ( 1 , result . axes [ self . axis ] . nlevels ) ) + [ 0 ] # temporarily saves the index names index_names = np . array ( result . axes [ self . axis ] . names ) # set index names to positions to avoid confusion result . axes [ self . axis ] . names = np . arange ( len ( index_names ) ) # place quantiles on the inside if isinstance ( result , Series ) : result = result . reorder_levels ( order ) else : result = result . reorder_levels ( order , axis = self . axis ) # restore the index names in order result . axes [ self . axis ] . names = index_names [ order ] # reorder rows to keep things sorted indices = ( np . arange ( result . shape [ self . axis ] ) . reshape ( [ len ( q ) , self . ngroups ] ) . T . flatten ( ) ) return result . take ( indices , axis = self . axis )