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

BUG: Resample doesn't work for timestamp[ns][pyarrow] #55989

Closed
3 tasks done
harrylojames opened this issue Nov 16, 2023 · 0 comments · Fixed by #56371
Closed
3 tasks done

BUG: Resample doesn't work for timestamp[ns][pyarrow] #55989

harrylojames opened this issue Nov 16, 2023 · 0 comments · Fixed by #56371
Labels
Arrow pyarrow functionality Bug Resample resample method

Comments

@harrylojames
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
from pandas import Timestamp
df = pd.DataFrame.from_dict({Timestamp('2022-03-31 01:00:00'): 1}, orient="index")
df.index = df.index.astype("timestamp[ns][pyarrow]")
df.resample("1min").mean()

Issue Description

Using resample with timestamp[ns][pyarrow] returns a TypeError

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 5
      3 df = pd.DataFrame.from_dict({Timestamp('2022-03-31 01:00:00'): 1}, orient="index")
      4 df.index = df.index.astype("timestamp[ns][pyarrow]")
----> 5 df.resample("1min").mean()

File ~\AppData\Local\pypoetry\Cache\virtualenvs\\lib\site-packages\pandas\core\generic.py:9439, in NDFrame.resample(self, rule, axis, closed, label, convention, kind, on, level, origin, offset, group_keys)
   9436 else:
   9437     axis = 0
-> 9439 return get_resampler(
   9440     cast("Series | DataFrame", self),
   9441     freq=rule,
   9442     label=label,
   9443     closed=closed,
   9444     axis=axis,
   9445     kind=kind,
   9446     convention=convention,
   9447     key=on,
   9448     level=level,
   9449     origin=origin,
   9450     offset=offset,
   9451     group_keys=group_keys,
   9452 )

File ~\AppData\Local\pypoetry\Cache\virtualenvs\\lib\site-packages\pandas\core\resample.py:1970, in get_resampler(obj, kind, **kwds)
   1966 """
   1967 Create a TimeGrouper and return our resampler.
   1968 """
   1969 tg = TimeGrouper(**kwds)
-> 1970 return tg._get_resampler(obj, kind=kind)

File ~\AppData\Local\pypoetry\Cache\virtualenvs\\lib\site-packages\pandas\core\resample.py:2160, in TimeGrouper._get_resampler(self, obj, kind)
   2151 elif isinstance(ax, TimedeltaIndex):
   2152     return TimedeltaIndexResampler(
   2153         obj,
   2154         timegrouper=self,
   (...)
   2157         gpr_index=ax,
   2158     )
-> 2160 raise TypeError(
   2161     "Only valid with DatetimeIndex, "
   2162     "TimedeltaIndex or PeriodIndex, "
   2163     f"but got an instance of '{type(ax).__name__}'"
   2164 )

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'

Expected Behavior

Commenting out the conversion to timestamp[ns][pyarrow] produces the expected behaviour.

import pandas as pd
from pandas import Timestamp
df = pd.DataFrame.from_dict({Timestamp('2022-03-31 01:00:00'): 1}, orient="index")
#df.index = df.index.astype("timestamp[ns][pyarrow]")
df.resample("1min").mean()

Installed Versions

INSTALLED VERSIONS

commit : 2a953cf
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 2.1.3
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.2
Cython : 3.0.2
pytest : 7.3.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.10.0
gcsfs : None
matplotlib : 3.7.3
numba : 0.57.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 2.0.23
tables : None
tabulate : 0.9.0
xarray : 2023.8.0
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@harrylojames harrylojames added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 16, 2023
@mroeschke mroeschke added Resample resample method Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug Resample resample method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants