Skip to content

BUG: the seconds attribute of .dt.components for pyarrow timestamp datatype seem faulty #57355

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
3 tasks done
MatusGasparik opened this issue Feb 11, 2024 · 3 comments · Fixed by #58052
Closed
3 tasks done
Assignees
Labels
Arrow pyarrow functionality Bug datetime.date stdlib datetime.date support

Comments

@MatusGasparik
Copy link

MatusGasparik commented Feb 11, 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

import pandas as pd

assert pd.__version__ == '2.2.0'

# example from the book "Effective Pandas 2 (by Matt Harrison)"
classes = ['cs106', 'cs150', 'hist205', 'hist206', 'hist207']

start_dates = (
    pd.Series([
        '2015-03-08',
        '2015-03-08',
        '2015-03-09',
        '2015-03-09',
        '2015-03-11'
    ], dtype='datetime64[ns]', index=classes
).astype('timestamp[ns][pyarrow]'))

end_dates = (
    pd.Series([
        '2015-05-28 23:59:59', 
        '2015-06-01 3:00:00', 
        '2015-06-03', 
        '2015-06-02 14:20', 
        '2015-06-01'
    ], dtype='datetime64[ns]', index=classes
).astype('timestamp[ns][pyarrow]'))

duration = (end_dates - start_dates)

Issue Description

These are the data:

print(duration)
cs106      81 days 23:59:59
cs150      85 days 03:00:00
hist205    86 days 00:00:00
hist206    85 days 14:20:00
hist207    82 days 00:00:00
dtype: duration[ns][pyarrow]

I noticed that calling .dt.components on the above duration object behaves differently for the 'timestamp[ns][pyarrow]' vs. the 'timedelta64[ns]' data types. For the former, the seconds attribute (column) give a very high value (and I assume it is total seconds for the 'HH:MM:SS' part.

print(duration.dt.components)

results in:

   days  hours  minutes  seconds  milliseconds  microseconds  nanoseconds
0    81     23       59    86399             0             0            0
1    85      3        0    10800             0             0            0
2    86      0        0        0             0             0            0
3    85     14       20    51600             0             0            0
4    82      0        0        0             0             0            0

Expected Behavior

Converting to pandas 1.x 'timedelta64[ns]' give an expected result:

print(duration.astype('timedelta64[ns]').dt.components)

results in:

         days  hours  minutes  seconds  milliseconds  microseconds  nanoseconds
cs106      81     23       59       59             0             0            0
cs150      85      3        0        0             0             0            0
hist205    86      0        0        0             0             0            0
hist206    85     14       20        0             0             0            0
hist207    82      0        0        0             0             0            0

Installed Versions

INSTALLED VERSIONS

commit : f538741
python : 3.12.1.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Sun Nov 6 23:31:13 PST 2022; root:xnu-8020.240.14~1/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

@MatusGasparik MatusGasparik added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 11, 2024
@rhshadrach
Copy link
Member

Thanks for the report. Confirmed on main, further investigations and PRs to fix are welcome!

@rhshadrach rhshadrach added datetime.date stdlib datetime.date support Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 15, 2024
@St0rmie
Copy link
Contributor

St0rmie commented Feb 26, 2024

Will try to work on this.

@St0rmie
Copy link
Contributor

St0rmie commented Feb 27, 2024

take

St0rmie added a commit to St0rmie/pandas that referenced this issue Mar 27, 2024
St0rmie added a commit to St0rmie/pandas that referenced this issue Mar 27, 2024
St0rmie added a commit to St0rmie/pandas that referenced this issue May 3, 2024
St0rmie added a commit to St0rmie/pandas that referenced this issue May 4, 2024
St0rmie added a commit to St0rmie/pandas that referenced this issue Jun 15, 2024
St0rmie added a commit to St0rmie/pandas that referenced this issue Jun 15, 2024
mroeschke pushed a commit that referenced this issue Jun 18, 2024
…incorrect values #57355 (#58052)

BUG: fixed Series.dt methods in ArrowDtype class that were returning incorrect time values. (#57355)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug datetime.date stdlib datetime.date support
Projects
None yet
3 participants