Skip to content

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

Merged
merged 1 commit into from
Sep 17, 2017
Merged

added nearest to resample + test #17498

merged 1 commit into from
Sep 17, 2017

Conversation

ab320012
Copy link
Contributor

@ab320012 ab320012 commented Sep 11, 2017

  • closes Resample nearest #17496
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

DataFrame.fillna
"""
return self._upsample('nearest', limit=limit)
nearest = nearest
Copy link
Member

Choose a reason for hiding this comment

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

Remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@codecov
Copy link

codecov bot commented Sep 11, 2017

Codecov Report

Merging #17498 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.92% <100%> (ø) ⬆️
#single 40.22% <66.66%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/resample.py 96.17% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46856c3...1195b49. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 11, 2017

Codecov Report

Merging #17498 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.99% <100%> (-0.03%) ⬇️
#single 40.2% <50%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/resample.py 96.17% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 63.23% <0%> (-1.82%) ⬇️
pandas/core/frame.py 97.77% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5cfdbb...82933d1. Read the comment docs.

@gfyoung gfyoung added the Resample resample method label Sep 11, 2017
@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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)
Copy link
Member

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.

@gfyoung
Copy link
Member

gfyoung commented Sep 11, 2017

not sure to push whats new entry for such simple change

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']:
Copy link
Contributor

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).

@pep8speaks
Copy link

pep8speaks commented Sep 12, 2017

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

@ab320012 ab320012 force-pushed the master branch 12 times, most recently from f6e6933 to da621bc Compare September 14, 2017 19:19
Copy link
Contributor

@jreback jreback left a 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.

@@ -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
Copy link
Contributor

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

Copy link
Contributor

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):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

versionadded tag

@@ -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')
Copy link
Contributor

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)
Copy link
Contributor

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

@ab320012 ab320012 force-pushed the master branch 2 times, most recently from 541892a to ea46a07 Compare September 15, 2017 12:06
@jreback jreback merged commit 26b461b into pandas-dev:master Sep 17, 2017
@jreback
Copy link
Contributor

jreback commented Sep 17, 2017

thanks @ab320012 nice add, and very responsive! keep em coming!

alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resample nearest
4 participants