diff --git a/doc/source/whatsnew/v0.18.1.txt b/doc/source/whatsnew/v0.18.1.txt index d386f32d35195..928fefd6ce17e 100644 --- a/doc/source/whatsnew/v0.18.1.txt +++ b/doc/source/whatsnew/v0.18.1.txt @@ -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 `. (:issue:`12727`) diff --git a/pandas/core/missing.py b/pandas/core/missing.py index dd78979a9da7c..09e8e8e1401ca 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -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): @@ -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)' diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py index 2efc9c9d97be7..091e36ad7c049 100644 --- a/pandas/tseries/tests/test_resample.py +++ b/pandas/tseries/tests/test_resample.py @@ -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