Skip to content

BUG: [pyarrow] AttributeError: 'Index' object has no attribute 'freq' #53644

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
2 of 3 tasks
randolf-scholz opened this issue Jun 13, 2023 · 0 comments · Fixed by #53652
Closed
2 of 3 tasks

BUG: [pyarrow] AttributeError: 'Index' object has no attribute 'freq' #53644

randolf-scholz opened this issue Jun 13, 2023 · 0 comments · Fixed by #53652
Labels
Arrow pyarrow functionality Bug Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@randolf-scholz
Copy link
Contributor

randolf-scholz commented Jun 13, 2023

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 numpy as np
import pandas as pd


t = pd.date_range("2023-01-01", "2023-01-04", freq="1h")
x = np.random.randn(len(t))
df = pd.DataFrame(x, index=t, columns=["values"])

df.to_parquet("frame.parquet")
df2 = pd.read_parquet("frame.parquet", dtype_backend="pyarrow")

df.loc[df.index[:-5]]  # ✔
df2.loc[df2.index[:-5]]  # ✘ AttributeError: 'Index' object has no attribute 'freq'

Issue Description

Indexing an index of type timestamp[us][pyarrow] with an index of type timestamp[us][pyarrow] fails with AttributeError: 'Index' object has no attribute 'freq'.

The issue seems to be occurring here:

if keyarr.dtype.kind in "mM":
# DTI/TDI.take can infer a freq in some cases when we dont want one
if isinstance(key, list) or (
isinstance(key, type(self))
# "Index" has no attribute "freq"
and key.freq is None # type: ignore[attr-defined]
):
keyarr = keyarr._with_freq(None)

Expected Behavior

It should yield the same result independent of the dtype backend.

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 965ceca9fd796940050d6fc817707bba1c4f9bff
python           : 3.11.3.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.19.0-43-generic
Version          : #44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 22 13:39:36 UTC 2
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 2.0.2
numpy            : 1.23.5
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 67.7.2
pip              : 23.1.2
Cython           : 0.29.34
pytest           : 7.3.1
hypothesis       : None
sphinx           : 7.0.0
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.9.2
html5lib         : None
pymysql          : 1.0.3
psycopg2         : None
jinja2           : 3.1.2
IPython          : 8.13.2
pandas_datareader: None
bs4              : 4.12.2
bottleneck       : None
brotli           : None
fastparquet      : 2023.4.0
fsspec           : 2023.5.0
gcsfs            : None
matplotlib       : 3.7.1
numba            : 0.57.0
numexpr          : 2.8.4
odfpy            : None
openpyxl         : 3.1.2
pandas_gbq       : None
pyarrow          : 12.0.0
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : 1.10.1
snappy           : None
sqlalchemy       : 1.4.48
tables           : 3.8.0
tabulate         : 0.9.0
xarray           : 2023.4.2
xlrd             : None
zstandard        : None
tzdata           : 2023.3
qtpy             : None
pyqt5            : None
@randolf-scholz randolf-scholz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 13, 2023
@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants