Skip to content

Categorical.fillna doesn't validate consistent kwargs #19682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomAugspurger opened this issue Feb 13, 2018 · 1 comment
Closed

Categorical.fillna doesn't validate consistent kwargs #19682

TomAugspurger opened this issue Feb 13, 2018 · 1 comment
Labels
API Design Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@TomAugspurger
Copy link
Contributor

In [3]: pd.Categorical(['a', 'b']).fillna(value='a', method='ffill')
Out[3]:
[a, b]
Categories (2, object): [a, b]

In [4]: pd.Series(pd.Categorical(['a', 'b'])).fillna(value='a', method='ffill')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-141070886f71> in <module>()
----> 1 pd.Series(pd.Categorical(['a', 'b'])).fillna(value='a', method='ffill')

~/sandbox/pandas-ip/pandas/pandas/core/series.py in fillna(self, value, method, axis, inplace, limit, downcast, **kwargs)
   2659                                           axis=axis, inplace=inplace,
   2660                                           limit=limit, downcast=downcast,
-> 2661                                           **kwargs)
   2662
   2663     @Appender(generic._shared_docs['replace'] % _shared_doc_kwargs)

~/sandbox/pandas-ip/pandas/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   4745         else:
   4746             if method is not None:
-> 4747                 raise ValueError('cannot specify both a fill method and value')
   4748
   4749             if len(self._get_axis(axis)) == 0:

ValueError: cannot specify both a fill method and value

Both of these should raise. PR coming shortly.

@TomAugspurger TomAugspurger added API Design Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Categorical Categorical Data Type labels Feb 13, 2018
@TomAugspurger
Copy link
Contributor Author

Will also fix / change so that both of these raise

In [2]: pd.Series(pd.Categorical(['a', 'b'])).fillna()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-82dc344cb1df> in <module>()
----> 1 pd.Series(pd.Categorical(['a', 'b'])).fillna()

~/sandbox/pandas-ip/pandas/pandas/core/series.py in fillna(self, value, method, axis, inplace, limit, downcast, **kwargs)
   2659                                           axis=axis, inplace=inplace,
   2660                                           limit=limit, downcast=downcast,
-> 2661                                           **kwargs)
   2662
   2663     @Appender(generic._shared_docs['replace'] % _shared_doc_kwargs)

~/sandbox/pandas-ip/pandas/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   4710         if value is None:
   4711             if method is None:
-> 4712                 raise ValueError('must specify a fill method or value')
   4713             if self._is_mixed_type and axis == 1:
   4714                 if inplace:

ValueError: must specify a fill method or value

In [3]: pd.Categorical(['a', 'b']).fillna()
Out[3]:
[a, b]
Categories (2, object): [a, b]

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Feb 13, 2018
@jreback jreback added this to the 0.23.0 milestone Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

2 participants