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

Series 'pct_change' with 'fill_method' broken #19873

WillAyd opened this Issue Feb 23, 2018 · 1 comment


None yet
2 participants

WillAyd commented Feb 23, 2018

The fill_method argument for pct_change does not have any effect on the calculated result. To illustrate:

>>> ser = pd.Series([np.nan, np.nan, 0, 2, 4, 6, np.nan, np.nan])
>>> ser.pct_change()
0         NaN
1         NaN
2         NaN
3         inf
4    1.000000
5    0.500000
6         NaN
7         NaN
dtype: float64

    # Will return same result as above
>>> ser.pct_change(fill_method='pad')
0         NaN
1         NaN
2         NaN
3         inf
4    1.000000
5    0.500000
6         NaN
7         NaN
dtype: float64

I would expect rows 6 and 7 above to be 0 as a result of the fill operation. The problem can be traced to the below line of code, where the mask is referencing the original values before any fill logic is applied:

mask = isna(_values_from_object(self))


commit: ce77b79
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None

pandas: 0.23.0.dev0+364.gce77b79b9.dirty
pytest: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.1.0
sphinx: 1.6.5
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: (dt dec pq3 ext lo64)
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None


This comment has been minimized.


WillAyd commented Feb 24, 2018

FWIW fill_method defaults to pad without specifying the keyword argument so both calls above are identical, but the point remains that no filling action actually occurs to return 0 instead of NaN where appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment