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: .dt.microsecond for pyarrow-backed Series returns 0 #59154

Closed
3 tasks done
MarcoGorelli opened this issue Jul 1, 2024 · 2 comments · Fixed by #59183
Closed
3 tasks done

BUG: .dt.microsecond for pyarrow-backed Series returns 0 #59154

MarcoGorelli opened this issue Jul 1, 2024 · 2 comments · Fixed by #59183
Labels
Arrow pyarrow functionality Bug Datetime Datetime data dtype

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Jul 1, 2024

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

In [22]: s = pd.Series(pd.date_range('2000', periods=3, freq='15ms'))

In [23]: s.dt.microsecond
Out[23]:
0        0
1    15000
2    30000
dtype: int32

In [24]: s.convert_dtypes(dtype_backend='pyarrow')
Out[24]:
0           2000-01-01 00:00:00
1    2000-01-01 00:00:00.015000
2    2000-01-01 00:00:00.030000
dtype: timestamp[ns][pyarrow]

In [25]: s.convert_dtypes(dtype_backend='pyarrow').dt.microsecond
Out[25]:
0    0
1    0
2    0
dtype: int64[pyarrow]

Issue Description

For non-pyarrow backed dtype, it returns the total number of microseconds since the last second

For pyarrow-backed, it just returns 0

Expected Behavior

In [25]: s.convert_dtypes(dtype_backend='pyarrow').dt.microsecond
Out[25]:
0        0
1    15000
2    30000
dtype: int64[pyarrow]

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.153.1-microsoft-standard-WSL2
Version : #1 SMP Fri Mar 29 23:14:13 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 2.0.0
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 65.5.0
pip : 24.0
Cython : None
pytest : 8.1.1
hypothesis : 6.100.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.23.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.3.1
gcsfs : None
matplotlib : 3.8.4
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@MarcoGorelli MarcoGorelli added Bug Needs Triage Issue that has not been reviewed by a pandas team member Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 1, 2024
@mroeschke mroeschke added the Datetime Datetime data dtype label Jul 1, 2024
@Aloqeely
Copy link
Member

Aloqeely commented Jul 4, 2024

This looks like an issue with pyarrow.

In [2]: import pyarrow as pa

In [3]: s = pd.Series(pd.date_range('2000', periods=3, freq='15ms'))

In [4]: pa.Array.from_pandas(s)
Out[4]:
<pyarrow.lib.TimestampArray object at 0x00000183A8E793C0>
[
  2000-01-01 00:00:00.000000000,
  2000-01-01 00:00:00.015000000,
  2000-01-01 00:00:00.030000000
]

In [5]: pa.compute.microsecond(pa.Array.from_pandas(s))
Out[5]:
<pyarrow.lib.Int64Array object at 0x00000183A8E7BDC0>
[
  0,
  0,
  0
]

@Aloqeely Aloqeely added the Upstream issue Issue related to pandas dependency label Jul 4, 2024
@MarcoGorelli MarcoGorelli removed the Upstream issue Issue related to pandas dependency label Jul 4, 2024
@MarcoGorelli
Copy link
Member Author

thanks for checking - looks like it's not a bug in pyarrow, but just that pyarrow's method does something different

https://arrow.apache.org/docs/python/generated/pyarrow.compute.microsecond.html

Millisecond returns number of microseconds since the last full millisecond

So, I think this needs working around in pandas

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