Skip to content

More informative exception when trying to use MS as period frequency #5340

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 6 commits into from

Conversation

cancan101
Copy link
Contributor

Closes #5332

@jtratner
Copy link
Contributor

I'm not convinced this is reasonable to do. I don't get a keyerror when using "MS" - I think it's just a backwards compatibility thing where MS is always made into milliseconds (which is what "L" means too).

@cancan101
Copy link
Contributor Author

@jtratner I thought you had originally been seeing the key error? When I use Pandas v0.12, I definitely am getting key error.

The ability to use MS to mean milliseconds is inconsistent. There are parts of the Pandas code that explicitly prevent this and others that do not.

@jtratner
Copy link
Contributor

@cancan101 seems like the underlying problem is that this fails poorly:

pd.Period('2013').asfreq(freq='L')

Also, Wakari version of pandas gets a KeyError on 'MS', guess I'm just special.

@cancan101
Copy link
Contributor Author

I actually think there are two issues here. One is that MS, in my opinion,
imcorrectly maps to L. The second problem is that L is not recognized as a
valid period frequency.

On Sunday, October 27, 2013, Jeff Tratner wrote:

@cancan101 https://github.com/cancan101 seems like the underlying
problem is that this fails poorly:

pd.Period('2013').asfreq(freq='L')

Also, Wakari version of pandas gets a KeyError on 'MS', guess I'm just
special.


Reply to this email directly or view it on GitHubhttps://github.com//pull/5340#issuecomment-27184392
.

@jtratner
Copy link
Contributor

Prefer to address both. Also, what should MS map to, if anything?

@jtratner
Copy link
Contributor

Actually, what I'd really prefer is that passing an unknown frequency raises ValueError("Unknown frequency: %s") vs. KeyError. It's okay to separate out 'L' /'MS', etc. But definitely should warn instead of just removing it.

@cancan101
Copy link
Contributor Author

Initially, I thought that MS should map to MonthBegin but in thinking about that, it doesn't make sense for a period. This is because a period encompasses both the start and end time stamps so Month (i.e. M) should be all that is needed to describe a "month" period. I think that MS should not map to anything. As for ValueError, that is what my new tests checks for: https://github.com/pydata/pandas/pull/5340/files#diff-f9b276c4aa39a6161726d8b43ce62516R496

initial = Period("2013")

self.assertEqual(initial.asfreq(freq="M", how="S"), Period('2013-01', 'M'))
self.assertRaises(ValueError, initial.asfreq, freq="MS", how="S")
Copy link
Contributor

Choose a reason for hiding this comment

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

please change one of these to have (a portion of) the text of the error message. Much easier to maintain that way (and adds really minimal performance hit).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@jtratner jtratner closed this in 2302973 Nov 6, 2013
@cancan101
Copy link
Contributor Author

@jtratner That commit does not fix this issue.

@cancan101
Copy link
Contributor Author

Or I should say, it solves the issue by having the period 'MS' map to 'L' correctly which I would argue is incorrect.

@jtratner
Copy link
Contributor

jtratner commented Nov 6, 2013

Ah, okay, I didn't realize, let's reopen this then.

@jtratner jtratner reopened this Nov 6, 2013
@jtratner
Copy link
Contributor

jtratner commented Nov 6, 2013

Probably the other should have said 'related to #5340' and fixes for the other PR.

@jtratner
Copy link
Contributor

jtratner commented Nov 6, 2013

Just FYI - when you put "fixes #<some issue#>" it autocloses that issue when you merge the PR.

@kevinastone
Copy link
Contributor

Sorry, this was my fault. I meant #5430 and mis-typed in the commit.

@jseabold
Copy link
Contributor

jseabold commented Jan 5, 2014

FWIW, from what I remember when this code was being written some years (!) ago, MS as a frequency (this is before the period concept existed in pandas) was meant to map to MonthBegin. It looks to me like MS -> milliseconds was added when it was decided that pandas would provide most/all of the capabilities that were in scikits.timeseries and they were using the mapping MS -> milliseconds. This PR looks like what I would also do to revert back to some consistency for MS. I'll check it out locally and let you know if I notice anything from the statsmodels usage side and my code.

@cancan101
Copy link
Contributor Author

@jseabold What are your thoughts on this PR?

@cancan101
Copy link
Contributor Author

@bump

@jseabold
Copy link
Contributor

Can you explain again why this shouldn't work?

pd.Period('2013').asfreq(freq='MS', how="S")

@jseabold
Copy link
Contributor

Nevermind. I see that using 'M' actually returns a start of the month timestamp. Odd. Yeah, this looks fine to me. At least it clears up the problem with the milliseconds.

@jreback
Copy link
Contributor

jreback commented Feb 11, 2014

@cancan101 where exactly is the inconsistency in error messages?

@jreback
Copy link
Contributor

jreback commented Apr 9, 2014

@cancan101 can you rebase and squash. Is this dependent on the offsets/period cleanup?

@cancan101
Copy link
Contributor Author

I do not believe this is dependent on the other PR.
On Apr 8, 2014 8:09 PM, "jreback" [email protected] wrote:

@cancan101 https://github.com/cancan101 can you rebase and squash. Is
this dependent on the offsets/period cleanup?

Reply to this email directly or view it on GitHubhttps://github.com//pull/5340#issuecomment-39916390
.

@jreback
Copy link
Contributor

jreback commented Apr 9, 2014

merged via 0b7e917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Frequency DateOffsets Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Period.asfreq broken for freq=MS
5 participants