Skip to content

Commit

Permalink
BUG: passing an invalid fill method to resample(..).fillna() caus…
Browse files Browse the repository at this point in the history
…es an odd error message

closes #12952
  • Loading branch information
jreback committed Apr 21, 2016
1 parent b3b166a commit b407683
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
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

0 comments on commit b407683

Please sign in to comment.