Skip to content

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

Merged

Conversation

cchwala
Copy link
Contributor

@cchwala cchwala commented Jan 18, 2018

As a first step, the initial commit just extends the resampling tests so that they fail when a misstyped string argument, e.g. for label, passes silently without raising.

I have the fix for the code ready and will commit when the tests have failed once.

@@ -963,6 +963,15 @@ 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)

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 as a separate test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. No problem.

@jreback jreback added Error Reporting Incorrect or improved errors from pandas Resample resample method labels Jan 18, 2018
@jreback
Copy link
Contributor

jreback commented Jan 19, 2018

tests look good. pls push the fix when you can.

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

Choose a reason for hiding this comment

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

These should probably be ValueErrors.

@@ -485,7 +485,7 @@ Groupby/Resample/Rolling

- Bug when grouping by a single column and aggregating with a class like ``list`` or ``tuple`` (:issue:`18079`)
- Fixed regression in :func:`DataFrame.groupby` which would not emit an error when called with a tuple key not in the index (:issue:`18798`)
-
- Bug in :func:`DataFrame.resample` which silently ignored unsupported (or misstyped) options for `label`, `closed` and `convention` (:issue:`19303`)
Copy link
Contributor

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 and convention.

@pep8speaks
Copy link

pep8speaks commented Jan 19, 2018

Hello @cchwala! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on January 21, 2018 at 15:47 Hours UTC

@codecov
Copy link

codecov bot commented Jan 19, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@b286789). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #19307   +/-   ##
=========================================
  Coverage          ?    91.5%           
=========================================
  Files             ?      150           
  Lines             ?    48745           
  Branches          ?        0           
=========================================
  Hits              ?    44606           
  Misses            ?     4139           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.87% <100%> (?)
#single 41.72% <0%> (?)
Impacted Files Coverage Δ
pandas/core/resample.py 96.43% <100%> (ø)

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 b286789...c026767. Read the comment docs.

Copy link
Contributor

@TomAugspurger TomAugspurger 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 @cchwala, ping us when the tests pass.

if closed not in {None, 'left', 'right'}:
raise ValueError('Unsupported value %s for `closed`' % closed)
if convention not in {None, 'start', 'end', 'e', 's'}:
raise ValueError('Unsupported value %s for `convention`'
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use '%', use .format() instead.

@@ -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',
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 here as a comment

s = Series(np.random.randn(14), index=rng)

# Check that wrong keyword argument strings raise an error
with pytest.raises(ValueError) as e_info:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback There is also a linting error here because of the unused e_info. I will also remove these, okay?

@jreback jreback added this to the 0.23.0 milestone Jan 21, 2018
@jreback jreback merged commit 55db35e into pandas-dev:master Jan 21, 2018
@jreback
Copy link
Contributor

jreback commented Jan 21, 2018

thanks @cchwala

@cchwala cchwala deleted the check_for_correct_label_argument_in_resample branch January 21, 2018 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Resample resample method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

resample() silently ignores misstyped str kwargs, e.g. for label
4 participants