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: Period constructor raises instead of ignoring when passing a string with extra precision(pico, femto, etc.) #50417

Merged
merged 5 commits into from
Jan 16, 2023

Conversation

lithomas1
Copy link
Member

@lithomas1 lithomas1 added Testing pandas testing functions or related to the test suite Period Period data type labels Dec 23, 2022
@lithomas1
Copy link
Member Author

Honestly, it might be worth to kill parse_time_string entirely. It seems like it is only used for Period, and some DatetimeIndex str slicing logic.

@MarcoGorelli interested?

@MarcoGorelli
Copy link
Member

I'll take a look, thanks for the ping!

@@ -386,7 +386,7 @@ cdef parse_datetime_string_with_reso(
&out_tzoffset, False
)
if not string_to_dts_failed:
if dts.ps != 0 or out_local:
if out_bestunit == NPY_DATETIMEUNIT.NPY_FR_ns or out_local:
Copy link
Member

Choose a reason for hiding this comment

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

makes sense. to be totally correct we might need to check for ps, fs, as?

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 point. What should be the error message we raise, or should we silently ignore?

On 1.5.2, doing pd.Period("1970/01/01 00:00:00.000000000111") gives me

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/_libs/tslibs/period.pyx", line 2579, in pandas._libs.tslibs.period.Period.__new__
  File "pandas/_libs/tslibs/parsing.pyx", line 369, in pandas._libs.tslibs.parsing.parse_time_string
  File "pandas/_libs/tslibs/parsing.pyx", line 431, in pandas._libs.tslibs.parsing.parse_datetime_string_with_reso
KeyError: 11

Timestamp seems to ignore the extra precision, so maybe we should match that here?

Copy link
Member

Choose a reason for hiding this comment

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

definitely better than the status quo. it might be reasonable to have Timestamp warn/raise instead of silently truncating, but thats out of scope.

@lithomas1 lithomas1 changed the title TST: Add test for Period construction from str with zero nanos BUG: Period constructor raises instead of ignoring when passing a string with extra precision(pico, femto, etc.) Dec 30, 2022
@@ -395,6 +395,12 @@ cdef parse_datetime_string_with_reso(
parsed = datetime(
dts.year, dts.month, dts.day, dts.hour, dts.min, dts.sec, dts.us
)
# Match Timestamp and drop picoseconds, femtoseconds, attoseconds
# The new resolution will just be nano
Copy link
Member

Choose a reason for hiding this comment

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

GH ref pointing back here?

@lithomas1 lithomas1 added this to the 2.0 milestone Jan 3, 2023
@lithomas1 lithomas1 requested review from jbrockmendel and removed request for jbrockmendel January 11, 2023 22:09
@lithomas1
Copy link
Member Author

ping @jbrockmendel

@jbrockmendel jbrockmendel merged commit 579e070 into pandas-dev:main Jan 16, 2023
@jbrockmendel
Copy link
Member

thanks @lithomas1

@lithomas1 lithomas1 deleted the test-period-zero-nanos branch January 16, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Period Period data type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants