-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DatetimeIndex::inferred_freq is misleading #5082
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
Comments
This is used a bit throughout the codebase (though not too much, |
@cpcloud Yeah, I did not think deprecation was realistic. I am more interested in just adding I am looking to move away from passing around The code that I am looking at that would benefit from freq = self.index.freqstr or self.index.inferred_freq
new_index = self.index.to_period(freq=freq) which I would like to change to:
allowing me to pass the freq object (rather than string) down to the next layer. |
+1 on |
@cancan101 why not: freq = getattr(self.index, 'offset', self.index.freq) |
@jtratner how does that help with inferred freq? |
@cancan101 sorry, I misread what you were trying to do. If you are going to change the internals to avoid the lookups for date ranges, why not just have inferred_freq return DateOffset? |
And then in the equality method for DateOffset, just let it return True if it matches its own rule code. |
hmmm ... |
Yeah, but unless you think people are trying to do string concatenation/multiplication with it, having |
@cancan101 well, if freq is exactly as expressive as offset, then you can just have the hash be the rule code right? |
and by rule code I mean what you pass to period index/datetime index for freq |
No. There is many to one mapping string to offset. |
@cancan101 well, you could pick one mapping to be the actual representation, hash however you want (doesn't really matter so long as it's consistent) and then have |
As an aside, |
No. object.hash(self) |
If a == b then hash(a) must == hash(b) |
Yep, but if a!=b, it does not have to be the case that hash(a) != hash(b) |
Think of bucketing in dict. If hash is different then they likely will be in different bins so eq won't get called. |
Correct. |
We don't control hash of strings so they won't be same. |
That being said do we need to make offset eq corresponding rule code? |
Do you think people rely on |
I don't know how people are using the value. It is a public property so I was just going to introduce a new property that returned the actual offset to avoid breaking people in whatever manner they use the string. |
The old field could eventually be deprecated if desired as the offset is richer and you can get to the string from the offset. |
it'd be great if DateOffset was just a subclass of str, would make this very simple. |
anyways, why don't you make up a PR that adds inferred_freq_offset along with whatever simplifications you think can be made internally - easier to think about in context, right? Sounds like you have a plan in mind - and not that big of a deal to add another property I guess. |
|
Don't forget
And it's being proposed to add:
I would also like an inferred frequency offset class to avoid working with strings but I think the proposed new property name will exacerbate the inconsistency. The best case scenario IMO is:
Given how public these are, I realize this is probably a pipe dream. I think it's how it should be done though. As an aside, it would be useful if DatetimeIndex inherited |
As for pipe dream, see the comment above: #5082 (comment) |
I think we should prepare for the API change the @patricktokeeffe suggests above
I think this is an easy API change rather than using
|
How about we make this API change in a separate PR? Since it involves some breaking API changes, I do not want to hold up this PR while we discuss the other changes. FWIW, I do think the API changes make sense. |
simply to make this (and remove I would have loved for you to separate all of these issues into separate PR's can you do that? |
What is the "that"? Making the API change? Yes. Splitting up this PR, I would prefer not. |
'that' means separating all of these issues to separate (or a smaller number of PRs). The problem is that you are doing bug fixes, enhancements, cleaning, and API changes all in one. Very hard to review. that said its ok; except for the I haven't found anything that breaks, so I don't see an issue. |
Okay I will make the API change in this PR but leave the commit separate to On Thu, Apr 3, 2014 at 6:48 PM, jreback [email protected] wrote:
|
ok grt (and I think a |
@jreback Are you familiar with the difference between |
|
Looking at these three methods on DatetimeIndex:
you would think that
freqstr
returns a string andinferred_freq
andfreq
return "frequencies" (i.e. offsets). In realityinferred_freq
is a string as well.I am not sure of the best way to deal with this issue. At the very least I would suggest adding a
inferred_freq_offset
property. Perhaps also deprecateinferred_freq
and create ainferred_freqstr
.Tracing this method, you find
_FrequencyInferer::get_freq
which returns a string rather than an Offset.The text was updated successfully, but these errors were encountered: