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: itemsize wrong for date32[day][pyarrow] dtype? #57948

Open
3 tasks done
MarcoGorelli opened this issue Mar 21, 2024 · 6 comments
Open
3 tasks done

BUG: itemsize wrong for date32[day][pyarrow] dtype? #57948

MarcoGorelli opened this issue Mar 21, 2024 · 6 comments
Assignees
Labels
Arrow pyarrow functionality Bug

Comments

@MarcoGorelli
Copy link
Member

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 pyarrow as pa
import pandas as pd

pd.ArrowDtype(pa.date32())  # date32[day][pyarrow]
pd.ArrowDtype(pa.date32()).itemsize  # 8

Issue Description

I think it should show 4? pa.date32() is 32 bits, so 4 bytes

Expected Behavior

pd.ArrowDtype(pa.date32()).itemsize # 4

Installed Versions

INSTALLED VERSIONS

commit : b033ca9
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.146.1-microsoft-standard-WSL2
Version : #1 SMP Thu Jan 11 04:09:03 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.1.0.dev0+761.gb033ca94e7
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.1.1
pip : 24.0
Cython : 3.0.8
pytest : 8.0.2
hypothesis : 6.98.15
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : 3.2.0
lxml.etree : 5.1.0
html5lib : 1.1
pymysql : 1.4.6
psycopg2 : 2.9.9
jinja2 : 3.1.3
IPython : 8.22.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : 1.3.8
fastparquet : 2024.2.0
fsspec : 2024.2.0
gcsfs : 2024.2.0
matplotlib : 3.8.3
numba : 0.59.0
numexpr : 2.9.0
odfpy : None
openpyxl : 3.1.2
pyarrow : 15.0.2
pyreadstat : 1.2.6
python-calamine : None
pyxlsb : 1.0.10
s3fs : 2024.2.0
scipy : 1.12.0
sqlalchemy : 2.0.27
tables : 3.9.2
tabulate : 0.9.0
xarray : 2024.2.0
xlrd : 2.0.1
zstandard : 0.22.0
tzdata : 2024.1
qtpy : 2.4.1
pyqt5 : None

@MarcoGorelli MarcoGorelli added Bug Arrow pyarrow functionality labels Mar 21, 2024
@MarcoGorelli
Copy link
Member Author

Not sure what to do here, as there isn't a numpy dtype corresponding to date32

@cache_readonly
def itemsize(self) -> int:
"""Return the number of bytes in this dtype"""
return self.numpy_dtype.itemsize

@mroeschke
Copy link
Member

I think it's OK to override ArrowDtype.itemsize to handle this case separately

@jorisvandenbossche
Copy link
Member

PyArrow data types of fixed width have a bit_width attribute that could be used here. That does raise for nested types, though at the moment we just return 8 from the numpy object dtype, which also doesn't necessarily makes sense.

In [13]: pd.ArrowDtype(pa.list_(pa.int32())).itemsize
Out[13]: 8

@longovin
Copy link

take

@echerrin
Copy link

take

@Charlie-H7
Copy link

I'm having a hard time trying to find what and where to find the relationship between numpy_dtype and the itemsize method. Going to the definition of itemsize method does not show an implementation of the method, so I'm not sure what it is doing.

pandas/pandas/core/dtypes/dtypes.py#L2213-L2216

Any help is appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug
Projects
None yet
Development

No branches or pull requests

6 participants