Skip to content

Panel resample by periods does not work in 0.17.1 for certain panels #11983

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
rekcahpassyla opened this issue Jan 7, 2016 · 3 comments
Closed
Labels
Bug Period Period data type Resample resample method

Comments

@rekcahpassyla
Copy link
Contributor

This code works in 0.15.2 but breaks in 0.17.1

import pandas as pd
import numpy as np

pd.show_versions()

items = ['foo']
major_axis = pd.date_range('2013-04-01', '2013-06-30')
minor_axis = [0]

p = pd.Panel(
    np.ones(major_axis.size).reshape(1, -1, 1),
    items=items,
    major_axis=major_axis
)

p.resample('Q', how='mean', axis=1, kind='period')

0.15.2:

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 26 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en_GB

pandas: 0.15.2
nose: 1.3.7
Cython: 0.22
numpy: 1.9.3
scipy: 0.16.0
statsmodels: None
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.1
pytz: 2015.7
bottleneck: 1.0.0
tables: 3.2.0
numexpr: 2.4.3
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.4
xlwt: 0.7.5
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
Out[1]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 1 (items) x 1 (major_axis) x 1 (minor_axis)
Items axis: foo to foo
Major_axis axis: 2013Q2 to 2013Q2
Minor_axis axis: 0 to 0

0.17.1:

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 26 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.17.1
nose: 1.3.7
pip: 7.1.2
setuptools: 19.1.1
Cython: 0.23.4
numpy: 1.10.2
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.4.3
openpyxl: None
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.7
lxml: None
bs4: 4.3.2
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.10
pymysql: None
psycopg2: None
Jinja2: None


In [11]: p.resample('Q', how='mean', axis=1, kind='period')
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-11-37b0fd9cdc67> in <module>()
----> 1 p.resample('Q', how='mean', axis=1, kind='period')

c:\python\envs\pandas-0.17\lib\site-packages\pandas\core\generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind,
loffset, limit, base)
   3641                               fill_method=fill_method, convention=convention,
   3642                               limit=limit, base=base)
-> 3643         return sampler.resample(self).__finalize__(self)
   3644
   3645     def first(self, offset):

c:\python\envs\pandas-0.17\lib\site-packages\pandas\tseries\resample.pyc in resample(self, obj)
     80
     81         if isinstance(ax, DatetimeIndex):
---> 82             rs = self._resample_timestamps()
     83         elif isinstance(ax, PeriodIndex):
     84             offset = to_offset(self.freq)

c:\python\envs\pandas-0.17\lib\site-packages\pandas\tseries\resample.pyc in _resample_timestamps(self, kind)
    285                 # downsample
    286                 grouped = obj.groupby(grouper, axis=self.axis)
--> 287                 result = grouped.aggregate(self._agg_method)
    288                 # GH2073
    289                 if self.fill_method is not None:

c:\python\envs\pandas-0.17\lib\site-packages\pandas\core\groupby.pyc in aggregate(self, arg, *args, **kwargs)
   3661         """
   3662         if isinstance(arg, compat.string_types):
-> 3663             return getattr(self, arg)(*args, **kwargs)
   3664
   3665         return self._aggregate_generic(arg, *args, **kwargs)

c:\python\envs\pandas-0.17\lib\site-packages\pandas\core\groupby.pyc in mean(self)
    764             self._set_selection_from_grouper()
    765             f = lambda x: x.mean(axis=self.axis)
--> 766             return self._python_agg_general(f)
    767
    768     def median(self):

c:\python\envs\pandas-0.17\lib\site-packages\pandas\core\groupby.pyc in _python_agg_general(self, func, *args, **kwargs)
   1223         # iterate through "columns" ex exclusions to populate output dict
   1224         output = {}
-> 1225         for name, obj in self._iterate_slices():
   1226             try:
   1227                 result, counts = self.grouper.agg_series(obj, f)

c:\python\envs\pandas-0.17\lib\site-packages\pandas\core\groupby.pyc in _iterate_slices(self)
   3637             slicer = lambda x: self._selected_obj[x]
   3638         else:
-> 3639             raise NotImplementedError("axis other than 0 is not supported")
   3640
   3641         for val in slice_axis:

NotImplementedError: axis other than 0 is not supported

@rekcahpassyla
Copy link
Contributor Author

Has to do with items axis being of length 1: This works in both 0.15.2 and 0.17.1

In [12]: p2 = pd.Panel(
   ....:     np.ones(2*major_axis.size).reshape(2, -1, 1),
   ....:     items=['foo', 'bar'],
   ....:     major_axis=major_axis,
   ....: )

In [13]:

In [13]: p2.resample('Q', how='mean', axis=1, kind='period')
Out[13]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 1 (major_axis) x 1 (minor_axis)
Items axis: foo to bar
Major_axis axis: 2013Q2 to 2013Q2
Minor_axis axis: 0 to 0

In [14]: pd.__version__
Out[14]: u'0.17.1'

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

this is barely tested. so not surprising its buggy.

@jreback jreback added this to the Next Major Release milestone Jan 7, 2016
@jreback jreback added the Period Period data type label Apr 11, 2016
@jreback jreback modified the milestones: won't fix, Next Major Release Jul 11, 2017
@jreback
Copy link
Contributor

jreback commented Jul 11, 2017

closing as Panel deprecated

@jreback jreback closed this as completed Jul 11, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Period Period data type Resample resample method
Projects
None yet
Development

No branches or pull requests

4 participants