Skip to content

Commit

Permalink
simplify method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ResidentMario committed Mar 26, 2017
1 parent 38f73e7 commit 8c128a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
15 changes: 10 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
is_datetime64_dtype,
is_timedelta64_dtype,
is_datetime64tz_dtype,
is_period_arraylike,
is_list_like,
is_dict_like,
is_re_compilable)
from pandas.types.cast import _maybe_promote, _maybe_upcast_putmask
from pandas.types.missing import isnull, notnull, is_valid_fill_value
from pandas.types.missing import isnull, notnull
from pandas.types.generic import ABCSeries, ABCPanel

from pandas.core.common import (_values_from_object,
Expand Down Expand Up @@ -3383,11 +3382,17 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,

@Appender(_shared_docs['fillna'] % _shared_doc_kwargs)
def fillna(self, value=None, method=None, axis=None, inplace=False,
limit=None, downcast=None, errors=None):
limit=None, downcast=None, errors='coerce'):
inplace = validate_bool_kwarg(inplace, 'inplace')

if not missing.maybe_fill(self, value, errors):
return self
try:
missing.validate_fill_value(self, value)
except TypeError:
if errors == 'ignore':
return
elif errors == 'raise':
raise
# if errors == 'coerce' continue

if isinstance(value, (list, tuple)):
raise TypeError('"value" parameter must be a scalar or dict, but '
Expand Down
23 changes: 7 additions & 16 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
is_float_dtype, is_datetime64_dtype,
is_datetime64tz_dtype, is_integer_dtype,
_ensure_float64, is_scalar,
needs_i8_conversion, is_integer,
is_period_arraylike)
needs_i8_conversion, is_integer)
from pandas.types.missing import isnull, is_valid_fill_value
from pandas.types.generic import ABCSeries

Expand Down Expand Up @@ -625,7 +624,7 @@ def fill_zeros(result, x, y, name, fill):
return result


def maybe_fill(obj, value, errors):
def validate_fill_value(obj, value):
"""
Fillna error coercion routine.
Expand Down Expand Up @@ -659,16 +658,8 @@ def maybe_fill(obj, value, errors):
fillna error coercion routine, returns whether or not to continue.
"""
if isinstance(obj, ABCSeries):
if errors is None or errors == 'coerce':
return True
else:
if not is_valid_fill_value(value, obj.dtype):
if errors == 'raise':
raise TypeError('"value" parameter must be compatible '
'with the {0} dtype, but you passed a '
'"{1}"'.format(obj.dtype,
type(value).__name__))
else: # errors == 'ignore'; short-circuit
return False
else:
return True
if not is_valid_fill_value(value, obj.dtype):
raise TypeError('"value" parameter must be compatible '
'with the {0} dtype, but you passed a '
'"{1}"'.format(obj.dtype,
type(value).__name__))
2 changes: 2 additions & 0 deletions pandas/types/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ def is_valid_fill_value(value, dtype):
value : scalar
dtype: string / dtype
"""
if isinstance(value, dict):
return True
if not is_scalar(value):
# maybe always raise?
# raise TypeError('"value" parameter must be a scalar or dict, but '
Expand Down

0 comments on commit 8c128a9

Please sign in to comment.