Description
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:
Line 6893 in a00154d
INSTALLED VERSIONS
commit: ce77b79
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
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: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None