Skip to content

BUG: pd.period_range ignores multiple of start frequency. #47598

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
wants to merge 5 commits into from

Conversation

jaheba
Copy link

@jaheba jaheba commented Jul 5, 2022

Fixes: #47465

@jaheba jaheba force-pushed the fix-period-range-multiple branch from 341da30 to 18cf834 Compare July 6, 2022 12:36
Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

Looks like this broke stuff

@jaheba
Copy link
Author

jaheba commented Jul 6, 2022

Hopefully that is fixed now.

@phofl However, during testing I found this behaviour odd:

In [1]: import pandas as pd

In [2]: p = pd.Period("2020", freq="Y")

In [3]: pd.Period(p, freq="3Y")
Out[3]: Period('2020', 'A-DEC')

In [4]: pd.Period(p, freq="3D")
Out[4]: Period('2020-12-31', '3D')

The freq argument is ignored when the value is already a Period and has the same base-freq. I assume this is also not intended?

@jaheba
Copy link
Author

jaheba commented Jul 6, 2022

This looks wrong:

elif is_period_object(value):
other = value
if freq is None or freq._period_dtype_code == other.freq._period_dtype_code:
ordinal = other.ordinal
freq = other.freq
else:
converted = other.asfreq(freq)
ordinal = converted.ordinal

Checking the _period_dtype_code should not be sufficient, if the .n do not match.

@phofl
Copy link
Member

phofl commented Jul 6, 2022

This might be deliberate, are there tests covering this?

@jaheba
Copy link
Author

jaheba commented Jul 6, 2022

This might be deliberate, are there tests covering this?

I would be very surprised by this, so let's see: #47613

@mroeschke mroeschke added the Period Period data type label Jul 22, 2022
@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 Aug 22, 2022
@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 Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Period Period data type Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pd.period_range ignores multiple of start frequency
3 participants