-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Series.asof fails for all NaN Series (GH15713) #15758
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
Changes from 5 commits
676a4e5
c78d687
4e26ab8
17d1d77
89fb6cf
6b745af
70c958f
3f9c7fd
04b7306
a080b9b
7448b96
b8f078a
af9a29b
bb63964
0765108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3971,6 +3971,9 @@ def asof(self, where, subset=None): | |
if not isinstance(where, Index): | ||
where = Index(where) if is_list else Index([where]) | ||
|
||
if self.isnull().values.all(): | ||
return pd.Series([np.nan]) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see if you can simplify this logic a bit (maybe set the name where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey @jreback , I made a small simplification, pls check if that's ok... if it's ok, now I think everything is good to go |
||
nulls = self.isnull() if is_series else self[subset].isnull().any(1) | ||
locs = self.index.asof_locs(where, ~(nulls.values)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
from pandas import (offsets, Series, notnull, | ||
isnull, date_range, Timestamp) | ||
|
||
from pandas.util.testing import assert_series_equal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to import this, you can use it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
import pandas.util.testing as tm | ||
|
||
from .common import TestData | ||
|
@@ -148,3 +150,8 @@ def test_errors(self): | |
s = Series(np.random.randn(N), index=rng) | ||
with self.assertRaises(ValueError): | ||
s.asof(s.index[0], subset='foo') | ||
|
||
# series is all nans | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the issue number as a comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
result = Series([np.nan]).asof([0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this a separate test? (as it is not related to errors). Eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a case not using zero as the argument? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
expected = Series([np.nan]) | ||
assert_series_equal(result, expected) |
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.
This will not work for a DataFrame (I mean: it will not be the correct return value, see the docstring)
Further, you can put this after the next line where
nulls
is defined and reuse thatThere 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.
done! thanks for the comments, feels great to learn how to contribute :)