-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
added nearest to resample + test #17498
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
pandas/core/resample.py
Outdated
DataFrame.fillna | ||
""" | ||
return self._upsample('nearest', limit=limit) | ||
nearest = nearest |
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.
Remove this line.
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.
done
Codecov Report
@@ Coverage Diff @@
## master #17498 +/- ##
==========================================
- Coverage 91.15% 91.13% -0.02%
==========================================
Files 163 163
Lines 49534 49537 +3
==========================================
- Hits 45153 45147 -6
- Misses 4381 4390 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17498 +/- ##
==========================================
- Coverage 91.25% 91.21% -0.05%
==========================================
Files 163 163
Lines 49614 49616 +2
==========================================
- Hits 45274 45255 -19
- Misses 4340 4361 +21
Continue to review full report at Codecov.
|
pandas/core/resample.py
Outdated
@@ -480,6 +480,21 @@ def backfill(self, limit=None): | |||
return self._upsample('backfill', limit=limit) | |||
bfill = backfill | |||
|
|||
def nearest(self, limit=None): | |||
""" | |||
Backward or forward fill values |
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 is not particularly descriptive, at least to me. Also, add a newline beneath this one.
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 copy and pasted the structure from surrounding code
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.
Well then, take advantage of this opportunity to improve upon it 😄
Series.fillna | ||
DataFrame.fillna | ||
""" | ||
return self._upsample('nearest', limit=limit) |
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.
Since you're returning something, add a "Returns" section too.
I think you can just say that we have added support for a new sampling method that...(for you to fill in) |
@@ -2960,7 +2960,7 @@ def test_methods(self): | |||
expected = g.B.apply(lambda x: getattr(x.resample('2s'), f)()) | |||
assert_series_equal(result, expected) | |||
|
|||
for f in ['backfill', 'ffill', 'asfreq']: | |||
for f in ['nearest', 'backfill', 'ffill', 'asfreq']: |
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.
let's add a test for this specifically to make sure its doing the right thing. IOW construct a frame with an expected result (rather than the auto generated one here which might or might now actually do nearest resampling, as it doesn't have nans).
Hello @ab320012! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 16, 2017 at 14:01 Hours UTC |
f6e6933
to
da621bc
Compare
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.
looks good. couple of comments.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -28,6 +28,8 @@ New features | |||
and :class:`~pandas.ExcelWriter` to work properly with the file system path protocol (:issue:`13823`) | |||
- Added ``skipna`` parameter to :func:`~pandas.api.types.infer_dtype` to | |||
support type inference in the presence of missing values (:issue:`17059`). | |||
- Added ``nearest`` method to :class:`~pandas.Resampler` to support |
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.
:class:`~pandas.Resampler.nearest` is added
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.
add in apt.rst
as well.
@@ -463,6 +467,26 @@ def pad(self, limit=None): | |||
return self._upsample('pad', limit=limit) | |||
ffill = pad | |||
|
|||
def nearest(self, limit=None): | |||
""" |
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.
versionadded tag
pandas/tests/test_resample.py
Outdated
@@ -2934,6 +2934,21 @@ def test_getitem_multiple(self): | |||
result = r['buyer'].count() | |||
assert_series_equal(result, expected) | |||
|
|||
def test_nearest(self): | |||
index = pd.date_range('1/1/2000', periods=3, freq='T') |
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.
add the issue number as a comment
'2000-01-01 00:02:00'], | ||
dtype='datetime64[ns]', | ||
freq='20S')) | ||
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.
can you add a test with limit
as well
541892a
to
ea46a07
Compare
thanks @ab320012 nice add, and very responsive! keep em coming! |
git diff upstream/master -u -- "*.py" | flake8 --diff