in core/maxframe/dataframe/statistics/quantile.py [0:0]
def _call_dataframe(self, a, inputs):
if self.numeric_only:
empty_df = build_empty_df(a.dtypes)
dtypes = empty_df._get_numeric_data().dtypes
else:
dtypes = a.dtypes
if isinstance(self.q, TENSOR_TYPE):
q_val = self.q
pd_index = pd.Index([], dtype=q_val.dtype)
name = None
store_index_value = False
else:
q_val = np.asanyarray(self.q)
if q_val.ndim == 0:
pd_index = pd.Index(q_val.reshape(1))
else:
pd_index = pd.Index(q_val)
name = self.q if q_val.size == 1 else None
store_index_value = True
tokenize_objects = (a, q_val, self.interpolation, type(self).__name__)
if q_val.ndim == 0 and self.axis == 0:
index_value = parse_index(dtypes.index, store_data=store_index_value)
shape = (len(dtypes),)
# calc dtype
dtype = self._calc_dtype_on_axis_1(a, dtypes)
return self.new_series(
inputs,
shape=shape,
dtype=dtype,
index_value=index_value,
name=name or dtypes.index.name,
)
elif q_val.ndim == 0 and self.axis == 1:
index_value = a.index_value
shape = (len(a),)
# calc dtype
dt = tensor_quantile(
empty(a.shape[1], dtype=find_common_type(list(dtypes))),
self.q,
interpolation=self.interpolation,
handle_non_numeric=not self.numeric_only,
).dtype
return self.new_series(
inputs,
shape=shape,
dtype=dt,
index_value=index_value,
name=name or index_value.name,
)
elif q_val.ndim == 1 and self.axis == 0:
shape = (len(q_val), len(dtypes))
index_value = parse_index(
pd_index, *tokenize_objects, store_data=store_index_value
)
dtype_list = []
for name in dtypes.index:
dtype_list.append(
tensor_quantile(
tensor_from_series(a[name]),
self.q,
interpolation=self.interpolation,
handle_non_numeric=not self.numeric_only,
).dtype
)
dtypes = pd.Series(dtype_list, index=dtypes.index)
return self.new_dataframe(
inputs,
shape=shape,
dtypes=dtypes,
index_value=index_value,
columns_value=parse_index(dtypes.index, store_data=True),
)
else:
assert q_val.ndim == 1 and self.axis == 1
shape = (len(q_val), a.shape[0])
index_value = parse_index(
pd_index, *tokenize_objects, store_data=store_index_value
)
pd_columns = a.index_value.to_pandas()
dtype_list = np.full(len(pd_columns), self._calc_dtype_on_axis_1(a, dtypes))
dtypes = pd.Series(dtype_list, index=pd_columns)
return self.new_dataframe(
inputs,
shape=shape,
dtypes=dtypes,
index_value=index_value,
columns_value=parse_index(
dtypes.index, store_data=True, key=a.index_value.key
),
)