-
-
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
Changes from all commits
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 |
---|---|---|
|
@@ -1329,6 +1329,14 @@ def test_upsample_with_limit(self): | |
expected = ts.reindex(result.index, method='ffill', limit=2) | ||
assert_series_equal(result, expected) | ||
|
||
def test_nearest_upsample_with_limit(self): | ||
rng = date_range('1/1/2000', periods=3, freq='5t') | ||
ts = Series(np.random.randn(len(rng)), rng) | ||
|
||
result = ts.resample('t').nearest(limit=2) | ||
expected = ts.reindex(result.index, method='nearest', limit=2) | ||
assert_series_equal(result, expected) | ||
|
||
def test_resample_ohlc(self): | ||
s = self.series | ||
|
||
|
@@ -2934,6 +2942,24 @@ def test_getitem_multiple(self): | |
result = r['buyer'].count() | ||
assert_series_equal(result, expected) | ||
|
||
def test_nearest(self): | ||
|
||
# GH 17496 | ||
# Resample nearest | ||
index = pd.date_range('1/1/2000', periods=3, freq='T') | ||
result = pd.Series(range(3), index=index).resample('20s').nearest() | ||
|
||
expected = pd.Series( | ||
np.array([0, 0, 1, 1, 1, 2, 2]), | ||
index=pd.DatetimeIndex( | ||
['2000-01-01 00:00:00', '2000-01-01 00:00:20', | ||
'2000-01-01 00:00:40', '2000-01-01 00:01:00', | ||
'2000-01-01 00:01:20', '2000-01-01 00:01:40', | ||
'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 commentThe reason will be displayed to describe this comment to others. Learn more. can you add a test with |
||
|
||
def test_methods(self): | ||
g = self.frame.groupby('A') | ||
r = g.resample('2s') | ||
|
@@ -2960,7 +2986,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 commentThe 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). |
||
result = getattr(r, f)() | ||
expected = g.apply(lambda x: getattr(x.resample('2s'), f)()) | ||
assert_frame_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.
versionadded tag