BUG: min/max on empty categorical fails by OliverHofkens · Pull Request #30227 · pandas-dev/pandas (original) (raw)
- tests added / passed
- passes
black pandas
- passes
git diff upstream/master -u -- "*.py" | flake8 --diff
- whatsnew entry
Currently on master, the following fails:
import pandas as pd
Empty Dataframe
df = pd.DataFrame({ "cat": pd.Categorical([], categories=list("ABC"), ordered=True), "val": pd.Series([], dtype="int64") })
df["cat"].max()
ValueError: zero-size array to reduction operation maximum which has no identity
Other dtypes return NaN
when calling min()
or max()
on an empty Series. This PR changes the behavior of Categoricals to be the same.
Note that current behavior causes a downstream bug in Dask here: dask/dask#5645, so this PR could fix that bug as well.