Skip to content

BUG: to_datetime with floats and unit not matching Timestamp #56037

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

Merged
merged 10 commits into from
Nov 22, 2023

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.

The edited sas test is unfortunate but i think OK overall. Will revisit once #56014 is addressed. Also i expect that behavior to change in the not-too-distant future to return non-nano anyway.

In a follow-up I'll try to de-duplicate cast_from_unit and cast_from_unit_vectorized.

@mroeschke mroeschke added the Datetime Datetime data dtype label Nov 18, 2023
@mroeschke mroeschke added the Non-Nano datetime64/timedelta64 with non-nanosecond resolution label Nov 22, 2023
@mroeschke mroeschke added this to the 2.2 milestone Nov 22, 2023
@mroeschke mroeschke merged commit d9f70b3 into pandas-dev:main Nov 22, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the bug-to_datetime-float-year branch November 22, 2023 19:14
@phofl
Copy link
Member

phofl commented Dec 8, 2023

This seems to have caused a pretty bad performance regression

https://asv-runner.github.io/asv-collection/pandas/#inference.ToDatetimeFromIntsFloats.time_nanosec_float64

@@ -232,6 +233,7 @@ def test_to_timedelta_on_missing_values_list(self, val):
actual = to_timedelta([val])
assert actual[0]._value == np.timedelta64("NaT").astype("int64")

@pytest.mark.xfail(not IS64, reason="Floating point error")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is incorrect: I'm getting an XPASS here.

My guess is that you've hit this on i386, probably due to i387 weirdness. However, this wouldn't affect other 32-bit architectures or i386 builds with -mfpmath=sse. Gentoo is switching towards the latter since i387 is simply causing too many floating-point issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

A PR to make the xfail condition more precise would be welcome

Copy link
Contributor

Choose a reason for hiding this comment

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

I know but I honestly have no clue how to detect the right case. At this point, I can think only of two options: either removing the xfail and ignoring i387-based x86 to support other 32-bit setups, or using an approximate comparison instead.

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

Successfully merging this pull request may close these issues.

4 participants