-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Series.asof uses reindex GH10343 #10873
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
Conversation
nice work! |
@@ -2461,6 +2461,10 @@ def asof(self, where): | |||
|
|||
If there is no good value, NaN is returned. | |||
|
|||
Note that this is really just a convenient shorthand for `Series.reindex`, | |||
and is equivalent to `s.dropna().reindex(where, method='ffill')` for | |||
an array of dates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"array of dates" -> is this now still restricted to dates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc string to me means something like: When it's an array of dates, that long formula is an equivalent way of doing it. I'm not familiar with the issue itself tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but with the new implementation this equivalence holds for all index types I think.
The only difference is that asof
tries to parse strings as dates, and reindex
not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd imagine we should either check that it's a date index, or do some more checking around the string coercion - otherwise you could get some funky errors if you have a string based index and you use pass in a string as where
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaximilianR That's a good catch, thanks! Previously it was date only, so the conversion was straightforward, but as you point out we do now have to check for the possibility of a string index.
I'd like to see this put in Tests should then move to |
@jreback Ok, I'll see what I can do. |
can you update according to comments |
@jreback Yup, will get it done this week, sorry about the delay. |
So I'm having a little difficulty combining this with
I don't think it's possible to get that result using reindex, (and I must admit I'm a little confused as to the use case where this is the desired behavior). I can of course still move the Incidently, I was unable to find anywhere outside its own tests where |
Where is the code that is creating that oddness? Happy to have a look. I couldn't find it in |
@MaximilianR Far as I've been able to figure out the call chain, it goes Presumably the intended behavior since it's explicitly tested for (see
|
@bwillers hmm, I don't think |
@jreback I think its a valid asof question ("what's the most recent value before or on 2010-02-01") but the fact that calling with a string returns a backfilled rather than forward filled value seems wrong. But then, there's an explicit test requiring this, so it seems likely this was added for some particular purpose I'm unaware of. |
See here for discussion on asof's handling of partial string labels: #9258 (comment) |
@bwillers I can't understand how that example is intended behavior. Do you (anyone?) know why that might be intended behavior? I think it's fine to drop the functionality of string coercion. If it didn't add material complication I would vote to keep it (i.e. whatever you pass into I can have a look at this in more detail this w/e if helpful. |
@MaximilianR I do not know, I only discovered it a few days ago. Any insight is appreciated. |
closing, pls reopen if you can fix according to comments |
closes #10343 as discussed in #10345 , changed
Series.asof
to usereindex
internally, and remove the unused leftovers from index classes. All existing tests in test_series.py:TestSeries.test_asof pass with the new implementation.