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: pd.Timedelta(big_int, unit=W) silent overflow #47268

Merged
merged 4 commits into from
Jun 7, 2022

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

Sorry, something went wrong.

@simonjayhawkins simonjayhawkins added Bug Timedelta Timedelta data type labels Jun 7, 2022
@@ -732,6 +732,7 @@ Timedelta
^^^^^^^^^
- Bug in :func:`astype_nansafe` astype("timedelta64[ns]") fails when np.nan is included (:issue:`45798`)
- Bug in constructing a :class:`Timedelta` with a ``np.timedelta64`` object and a ``unit`` sometimes silently overflowing and returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`46827`)
- Bug in constructing a :class:`Timedelta` from a large integer or float with ``unit="W"`` silently overflowing and returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`47268`)
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add a note in the Other API Changes section mentioning that various timstamp/timedelta constructors that would overflow now raise a OutOfBoundsTimedelta/OutOfBoundsTimestamp instead of an OverflowError (they appear to be based off of different subclasses).

Should hopefully be a catchall for all these improvements you've been making

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, updated

@mroeschke mroeschke merged commit 4ea3efe into pandas-dev:main Jun 7, 2022
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the bug-pfu branch June 7, 2022 19:17
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
* BUG: pd.Timedelta(big_int, unit=W) silent overflow

* GH ref

* note exception changes in whatsnew
@behrenhoff
Copy link
Contributor

behrenhoff commented Sep 23, 2022

According to the release notes of pandas 1.5.0

Operations with Timestamp or Timedelta that would previously raise OverflowError instead raise OutOfBoundsDatetime or OutOfBoundsTimedelta where appropriate (GH47268)

However, pd.Timedelta(seconds=60) / 1e-9 still raises an OverflowError. Is that intended? From the changelog, it seems this should return a OutOfBoundsTimedelta instead.

@jbrockmendel
Copy link
Member Author

still raises an OverflowError. Is that intended

No. PR to fix cases we missed would be welcome.

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

Successfully merging this pull request may close these issues.

None yet

4 participants