Skip to content

BUG: passing an invalid fill method to resample(..).fillna() causes an odd error message #12952

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.18.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Bug Fixes

- Bug in ``.drop()`` with a non-unique ``MultiIndex``. (:issue:`12701`)
- Bug in ``.concat`` of datetime tz-aware and naive DataFrames (:issue:`12467`)

- Bug in correctly raising a ``ValueError`` in ``.resample(..).fillna(..)`` when passing a non-string (:issue:`12952`)

- Bug in ``Timestamp.__repr__`` that caused ``pprint`` to fail in nested structures (:issue:`12622`)
- Bug in ``Timedelta.min`` and ``Timedelta.max``, the properties now report the true minimum/maximum ``timedeltas`` as recognized by Pandas. See :ref:`documentation <timedeltas.limitations>`. (:issue:`12727`)
Expand Down
14 changes: 8 additions & 6 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas.core.common as com
import pandas.algos as algos
import pandas.lib as lib
from pandas.compat import range
from pandas.compat import range, string_types


def mask_missing(arr, values_to_mask):
Expand Down Expand Up @@ -60,11 +60,13 @@ def mask_missing(arr, values_to_mask):
def clean_fill_method(method, allow_nearest=False):
if method is None:
return None
method = method.lower()
if method == 'ffill':
method = 'pad'
if method == 'bfill':
method = 'backfill'

if isinstance(method, string_types):
method = method.lower()
if method == 'ffill':
method = 'pad'
elif method == 'bfill':
method = 'backfill'

valid_methods = ['pad', 'backfill']
expecting = 'pad (ffill) or backfill (bfill)'
Expand Down
3 changes: 3 additions & 0 deletions pandas/tseries/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ def test_fillna(self):
result = r.fillna(method='bfill')
assert_series_equal(result, expected)

with self.assertRaises(ValueError):
r.fillna(0)

def test_apply_without_aggregation(self):

# both resample and groupby should work w/o aggregation
Expand Down