Skip to content
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

DOC: better warning on chained resample(...) #13520

Closed
chris-b1 opened this issue Jun 27, 2016 · 5 comments
Closed

DOC: better warning on chained resample(...) #13520

chris-b1 opened this issue Jun 27, 2016 · 5 comments
Labels
Deprecate Functionality to remove in pandas Resample resample method
Milestone

Comments

@chris-b1
Copy link
Contributor

Code Sample, a copy-pastable example if possible

In [49]: df = pd.DataFrame({'a': 1.}, index=pd.date_range('2014-01-01', '2015-12-31'))

In [50]: df.resample('M').pct_change()
FutureWarning: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)
  if __name__ == '__main__':
Out[50]: 
              a
2014-01-31  NaN
<snip>

Expected Output

no warning

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.0
setuptools: 20.2.2
Cython: 0.22.1
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.6.1
xarray: None
IPython: 4.0.3
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: 2.0.2
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9.2
apiclient: 1.5.0
sqlalchemy: 1.0.5
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: 0.2.0
@chris-b1
Copy link
Contributor Author

chris-b1 commented Jun 27, 2016

Actually, this isn't spurious - what I meant to write is this. I'll leave this open - I think the warning could be better, to make it more clear that the mean of the data is being taken.

df.resample('M').last().pct_change()

@chris-b1 chris-b1 changed the title Spurious warning on resample(...).pct_change() DOC: better warning on chained resample(...) Jun 27, 2016
@jorisvandenbossche
Copy link
Member

Do you have a suggestion for a better warning? (PR's welcome :-))

df.resample('M').last().pct_change()

It's not fully clear what you mean with this

@jorisvandenbossche jorisvandenbossche added Resample resample method Deprecate Functionality to remove in pandas labels Jun 27, 2016
@chris-b1
Copy link
Contributor Author

chris-b1 commented Jun 27, 2016

I'll do a PR, what I want it to say is (in essence, hopefully in less words) -

.resample() is a deferred operation. You used that deferred object as if it were a {klass} - this materializes the deferred object by taking the mean() of each date group, which is deprecated behavior. Update your code <...>

What I was actually trying to do is take the month over month percent change - which is what .last().pct_change() does. But I forgot the last, so it took the mean of month, then the pct_change of those means.

@chris-b1 chris-b1 reopened this Jun 27, 2016
@jreback
Copy link
Contributor

jreback commented Jun 27, 2016

yes this is mainly for back-compat.

basically in < 0.18.0 you should have been doing

df.resample('M', how='mean').pct_change()

and so in >= 0.18.0 you implicity get this. It IS correct actually. I think the warning could also include the deferred op reference (e.g. pct_change()) I suppose, BUT the warning actually comes out before.

You might have a look at Resampler.plot().

@chris-b1 chris-b1 mentioned this issue Jul 16, 2016
4 tasks
@jreback jreback added this to the 0.19.0 milestone Jul 18, 2016
@jreback
Copy link
Contributor

jreback commented Jul 19, 2016

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants