MCPcopy Create free account
hub / github.com/dask/dask / describe_numeric_aggregate

Function describe_numeric_aggregate

dask/dataframe/methods.py:190–234  ·  view source on GitHub ↗
(
    stats,
    name=None,
    is_timedelta_col=False,
    is_datetime_col=False,
    unit="ns",
)

Source from the content-addressed store, hash-verified

188
189
190def describe_numeric_aggregate(
191 stats,
192 name=None,
193 is_timedelta_col=False,
194 is_datetime_col=False,
195 unit="ns",
196):
197 unit = unit or "ns"
198 assert len(stats) == 6
199 count, mean, std, min, q, max = stats
200
201 if is_series_like(count):
202 typ = type(count.to_frame())
203 else:
204 typ = type(q)
205
206 if is_timedelta_col:
207 mean = pd.to_timedelta(mean, unit=unit).as_unit(unit)
208 std = pd.to_timedelta(std, unit=unit).as_unit(unit)
209 min = pd.to_timedelta(min, unit=unit).as_unit(unit)
210 max = pd.to_timedelta(max, unit=unit).as_unit(unit)
211 q = q.apply(lambda x: pd.to_timedelta(x, unit=unit).as_unit(unit))
212
213 if is_datetime_col:
214 # mean is not implemented for datetime
215 min = pd.to_datetime(min, unit=unit).as_unit(unit)
216 max = pd.to_datetime(max, unit=unit).as_unit(unit)
217 q = q.apply(lambda x: pd.to_datetime(x, unit=unit).as_unit(unit))
218
219 if is_datetime_col:
220 part1 = typ([count, min], index=["count", "min"])
221 else:
222 part1 = typ([count, mean, std, min], index=["count", "mean", "std", "min"])
223
224 q.index = [f"{l * 100:g}%" for l in tolist(q.index)]
225 if is_series_like(q) and typ != type(q):
226 q = q.to_frame()
227 part3 = typ([max], index=["max"])
228
229 result = concat([part1, q, part3], sort=False)
230
231 if is_series_like(result):
232 result.name = name
233
234 return result
235
236
237def describe_nonnumeric_aggregate(stats, name):

Callers 1

operationMethod · 0.90

Calls 5

is_series_likeFunction · 0.90
tolistFunction · 0.90
concatFunction · 0.90
to_frameMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected