-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
FIX: Raise errors when wrong string arguments are passed to resample
#19307
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 3 commits
c985ee1
b05df91
1149226
24bcb98
9eaae6c
432332e
e65fb29
c026767
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 |
---|---|---|
|
@@ -1061,6 +1061,16 @@ class TimeGrouper(Grouper): | |
def __init__(self, freq='Min', closed=None, label=None, how='mean', | ||
axis=0, fill_method=None, limit=None, loffset=None, | ||
kind=None, convention=None, base=0, **kwargs): | ||
# Check for correctness of the keyword arguments which would | ||
# otherwise silently use the default if misspelled | ||
if label not in {None, 'left', 'right'}: | ||
raise AttributeError('Unsupported value %s for `label`' % label) | ||
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. These should probably be |
||
if closed not in {None, 'left', 'right'}: | ||
raise AttributeError('Unsupported value %s for `closed`' % closed) | ||
if convention not in {None, 'start', 'end', 'e', 's'}: | ||
raise AttributeError('Unsupported value %s for `convention`' | ||
% convention) | ||
|
||
freq = to_offset(freq) | ||
|
||
end_types = set(['M', 'A', 'Q', 'BM', 'BA', 'BQ', 'W']) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -963,6 +963,7 @@ def test_resample_basic(self): | |
rng = date_range('1/1/2000 00:00:00', '1/1/2000 00:13:00', freq='min', | ||
name='index') | ||
s = Series(np.random.randn(14), index=rng) | ||
|
||
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 as a separate test. 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. Yes. No problem. |
||
result = s.resample('5min', closed='right', label='right').mean() | ||
|
||
exp_idx = date_range('1/1/2000', periods=4, freq='5min', name='index') | ||
|
@@ -985,6 +986,19 @@ def test_resample_basic(self): | |
expect = s.groupby(grouper).agg(lambda x: x[-1]) | ||
assert_series_equal(result, expect) | ||
|
||
def test_resample_string_kwargs(self): | ||
rng = date_range('1/1/2000 00:00:00', '1/1/2000 00:13:00', freq='min', | ||
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. add the issue number here as a comment |
||
name='index') | ||
s = Series(np.random.randn(14), index=rng) | ||
|
||
# Check that wrong keyword argument strings raise an error | ||
with pytest.raises(AttributeError) as e_info: | ||
s.resample('5min', label='righttt').mean() | ||
with pytest.raises(AttributeError) as e_info: | ||
s.resample('5min', closed='righttt').mean() | ||
with pytest.raises(AttributeError) as e_info: | ||
s.resample('5min', convention='starttt').mean() | ||
|
||
def test_resample_how(self): | ||
rng = date_range('1/1/2000 00:00:00', '1/1/2000 00:13:00', freq='min', | ||
name='index') | ||
|
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.
Use double backticks for
label
,closed
andconvention
.