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: Prevent OutOfBoundsDatetime error for constructing tz-aware series from list #54620

Closed
wants to merge 9 commits into from

Conversation

AdrianDAlessandro
Copy link
Contributor

@AdrianDAlessandro AdrianDAlessandro commented Aug 18, 2023

Note that this PR only fixes the case where the units are explicitly specified and it is a timezone-aware datetime. The more general case(s) appears to be more complicated.

@AdrianDAlessandro
Copy link
Contributor Author

@jorisvandenbossche

@mroeschke mroeschke added Timezones Timezone data dtype Non-Nano datetime64/timedelta64 with non-nanosecond resolution labels Aug 18, 2023
@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Sep 21, 2023
@@ -2182,7 +2182,8 @@ def _sequence_to_dt64ns(
Returns
-------
result : numpy.ndarray
The sequence converted to a numpy array with dtype ``datetime64[ns]``.
The sequence converted to a numpy array with dtype ``datetime64[unit]``.
Where `unit` is ns unless specified otherwise.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"specified otherwise" -> "specified otherwise by out_unit"

@@ -1148,6 +1148,15 @@ def test_constructor_with_datetime_tz(self):
result = DatetimeIndex(s, freq="infer")
tm.assert_index_equal(result, dr)

def test_constructor_with_datetime_tz_ms(self):
# explicit frequency
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# GH#54620 explicit frequency

@jbrockmendel
Copy link
Member

does this need a whatsnew for the bugfix?

@jbrockmendel
Copy link
Member

@AdrianDAlessandro can you address comments and merge main

@AdrianDAlessandro
Copy link
Contributor Author

Yes, sorry I haven't been able to find time to continue working on this. I'm not convinced it's fully finished because the original bug is only for a timezone-aware series, which this fixes, but the bug also happens with the more generic case of all Datetime Series.

This will require further changes to the Cython code in tslib.pyx, specifically the array_to_datetime function. But I've never really worked with Python outside of this PR.

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Oct 22, 2023
@AdrianDAlessandro
Copy link
Contributor Author

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

Done

@mroeschke mroeschke reopened this Oct 23, 2023
@@ -1148,6 +1148,15 @@ def test_constructor_with_datetime_tz(self):
result = DatetimeIndex(s, freq="infer")
tm.assert_index_equal(result, dr)

def test_constructor_with_datetime_tz_ms(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this will also fix .astype to non-nano. can you add a test for that

@jbrockmendel
Copy link
Member

request for a test for .astype, otherwise LGTM

@@ -27,7 +27,7 @@
PeriodArray,
TimedeltaArray,
)
from pandas.core.arrays.datetimes import _sequence_to_dt64ns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we no longer test this function directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Non-Nano datetime64/timedelta64 with non-nanosecond resolution Stale Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Series([big_timestamp], dtype=pd.DatetimeTZDtype("us", "US/Pacific")) raises
3 participants