Skip to content

Commit 797baf9

Browse files
committed
BUG: passing an invalid fill method to resample(..).fillna() causes an odd error message
Author: Jeff Reback <[email protected]> Closes #12952 from jreback/fillna and squashes the following commits: b407683 [Jeff Reback] BUG: passing an invalid fill method to ``resample(..).fillna()`` causes an odd error message
1 parent b3b166a commit 797baf9

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

doc/source/whatsnew/v0.18.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Bug Fixes
280280

281281
- Bug in ``.drop()`` with a non-unique ``MultiIndex``. (:issue:`12701`)
282282
- Bug in ``.concat`` of datetime tz-aware and naive DataFrames (:issue:`12467`)
283-
283+
- Bug in correctly raising a ``ValueError`` in ``.resample(..).fillna(..)`` when passing a non-string (:issue:`12952`)
284284

285285
- Bug in ``Timestamp.__repr__`` that caused ``pprint`` to fail in nested structures (:issue:`12622`)
286286
- 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`)

pandas/core/missing.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pandas.core.common as com
88
import pandas.algos as algos
99
import pandas.lib as lib
10-
from pandas.compat import range
10+
from pandas.compat import range, string_types
1111

1212

1313
def mask_missing(arr, values_to_mask):
@@ -60,11 +60,13 @@ def mask_missing(arr, values_to_mask):
6060
def clean_fill_method(method, allow_nearest=False):
6161
if method is None:
6262
return None
63-
method = method.lower()
64-
if method == 'ffill':
65-
method = 'pad'
66-
if method == 'bfill':
67-
method = 'backfill'
63+
64+
if isinstance(method, string_types):
65+
method = method.lower()
66+
if method == 'ffill':
67+
method = 'pad'
68+
elif method == 'bfill':
69+
method = 'backfill'
6870

6971
valid_methods = ['pad', 'backfill']
7072
expecting = 'pad (ffill) or backfill (bfill)'

pandas/tseries/tests/test_resample.py

+3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ def test_fillna(self):
356356
result = r.fillna(method='bfill')
357357
assert_series_equal(result, expected)
358358

359+
with self.assertRaises(ValueError):
360+
r.fillna(0)
361+
359362
def test_apply_without_aggregation(self):
360363

361364
# both resample and groupby should work w/o aggregation

0 commit comments

Comments
 (0)