Skip to content

BUG: Series.replace with value=None explicitly #45081

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

Merged
merged 3 commits into from
Dec 29, 2021

Conversation

jbrockmendel
Copy link
Member

Not sure if there is a way to keep the default values rendered in the docs unchanged.

@jreback jreback added this to the 1.4 milestone Dec 28, 2021
@jreback jreback added Bug replace replace method Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Dec 28, 2021
@jreback
Copy link
Contributor

jreback commented Dec 28, 2021

i think doc-string needs updating

> /home/runner/work/pandas/pandas/pandas/core/generic.py:6801: DocTestFailure
_________________ [doctest] pandas.core.series.Series.replace __________________
5211     dtype: object
5212 
5213     When ``value=None`` and `to_replace` is a scalar, list or
5214     tuple, `replace` uses the method parameter (default 'pad') to do the
5215     replacement. So this is why the 'a' values are being replaced by 10
5216     in rows 1 and 2 and 'b' in row 4 in this case.
5217     The command ``s.replace('a', None)`` is actually equivalent to
5218     ``s.replace(to_replace='a', value=None, method='pad')``:
5219 
5220     >>> s.replace('a', None)
Differences (unified diff with -expected +actual):
    @@ -1,6 +1,6 @@
    -0    10
    -1    10
    -2    10
    -3     b
    -4     b
    +0      10
    +1    None
    +2    None
    +3       b
    +4    None
     dtype: object

@jreback jreback merged commit af76bd5 into pandas-dev:master Dec 29, 2021
@jreback
Copy link
Contributor

jreback commented Dec 29, 2021

very nice!

@jbrockmendel jbrockmendel deleted the issues-replace branch December 29, 2021 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate replace replace method
Projects
None yet
2 participants