| 236 | |
| 237 | |
| 238 | def describe_nonnumeric_aggregate(stats, name): |
| 239 | args_len = len(stats) |
| 240 | |
| 241 | is_datetime_column = args_len == 5 |
| 242 | is_categorical_column = args_len == 3 |
| 243 | |
| 244 | assert is_datetime_column or is_categorical_column |
| 245 | |
| 246 | if is_categorical_column: |
| 247 | nunique, count, top_freq = stats |
| 248 | else: |
| 249 | nunique, count, top_freq, min_ts, max_ts = stats |
| 250 | |
| 251 | # input was empty dataframe/series |
| 252 | if len(top_freq) == 0: |
| 253 | data = [0, 0] |
| 254 | index = ["count", "unique"] |
| 255 | dtype = None |
| 256 | data.extend([np.nan, np.nan]) |
| 257 | index.extend(["top", "freq"]) |
| 258 | dtype = object |
| 259 | result = pd.Series(data, index=index, dtype=dtype, name=name) |
| 260 | return result |
| 261 | |
| 262 | top = top_freq.index[0] |
| 263 | freq = top_freq.iloc[0] |
| 264 | |
| 265 | index = ["unique", "count", "top", "freq"] |
| 266 | values = [nunique, count] |
| 267 | |
| 268 | if is_datetime_column: |
| 269 | tz = top.tz |
| 270 | top = pd.Timestamp(top) |
| 271 | if top.tzinfo is not None and tz is not None: |
| 272 | # Don't tz_localize(None) if key is already tz-aware |
| 273 | top = top.tz_convert(tz) |
| 274 | else: |
| 275 | top = top.tz_localize(tz) |
| 276 | |
| 277 | first = pd.Timestamp(min_ts, tz=tz) |
| 278 | last = pd.Timestamp(max_ts, tz=tz) |
| 279 | index.extend(["first", "last"]) |
| 280 | values.extend([top, freq, first, last]) |
| 281 | else: |
| 282 | values.extend([top, freq]) |
| 283 | |
| 284 | return pd.Series(values, index=index, name=name) |
| 285 | |
| 286 | |
| 287 | def _cum_aggregate_apply(aggregate, x, y): |