Skip to content

Commit 24fd4a2

Browse files
committed
simplify method signature
1 parent afc7266 commit 24fd4a2

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

Diff for: pandas/core/generic.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
is_datetime64_dtype,
2121
is_timedelta64_dtype,
2222
is_datetime64tz_dtype,
23-
is_period_arraylike,
2423
is_list_like,
2524
is_dict_like,
2625
is_re_compilable)
2726
from pandas.types.cast import maybe_promote, maybe_upcast_putmask
28-
from pandas.types.missing import isnull, notnull, is_valid_fill_value
27+
from pandas.types.missing import isnull, notnull
2928
from pandas.types.generic import ABCSeries, ABCPanel
3029

3130
from pandas.core.common import (_values_from_object,
@@ -3373,11 +3372,17 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
33733372

33743373
@Appender(_shared_docs['fillna'] % _shared_doc_kwargs)
33753374
def fillna(self, value=None, method=None, axis=None, inplace=False,
3376-
limit=None, downcast=None, errors=None):
3375+
limit=None, downcast=None, errors='coerce'):
33773376
inplace = validate_bool_kwarg(inplace, 'inplace')
33783377

3379-
if not missing.maybe_fill(self, value, errors):
3380-
return self
3378+
try:
3379+
missing.validate_fill_value(self, value)
3380+
except TypeError:
3381+
if errors == 'ignore':
3382+
return
3383+
elif errors == 'raise':
3384+
raise
3385+
# if errors == 'coerce' continue
33813386

33823387
if isinstance(value, (list, tuple)):
33833388
raise TypeError('"value" parameter must be a scalar or dict, but '

Diff for: pandas/core/missing.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
is_float_dtype, is_datetime64_dtype,
1313
is_datetime64tz_dtype, is_integer_dtype,
1414
_ensure_float64, is_scalar,
15-
needs_i8_conversion, is_integer,
16-
is_period_arraylike)
15+
needs_i8_conversion, is_integer)
1716
from pandas.types.missing import isnull, is_valid_fill_value
1817
from pandas.types.generic import ABCSeries
1918

@@ -621,7 +620,7 @@ def fill_zeros(result, x, y, name, fill):
621620
return result
622621

623622

624-
def maybe_fill(obj, value, errors):
623+
def validate_fill_value(obj, value):
625624
"""
626625
627626
Fillna error coercion routine.
@@ -655,16 +654,8 @@ def maybe_fill(obj, value, errors):
655654
fillna error coercion routine, returns whether or not to continue.
656655
"""
657656
if isinstance(obj, ABCSeries):
658-
if errors is None or errors == 'coerce':
659-
return True
660-
else:
661-
if not is_valid_fill_value(value, obj.dtype):
662-
if errors == 'raise':
663-
raise TypeError('"value" parameter must be compatible '
664-
'with the {0} dtype, but you passed a '
665-
'"{1}"'.format(obj.dtype,
666-
type(value).__name__))
667-
else: # errors == 'ignore'; short-circuit
668-
return False
669-
else:
670-
return True
657+
if not is_valid_fill_value(value, obj.dtype):
658+
raise TypeError('"value" parameter must be compatible '
659+
'with the {0} dtype, but you passed a '
660+
'"{1}"'.format(obj.dtype,
661+
type(value).__name__))

Diff for: pandas/types/missing.py

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ def is_valid_fill_value(value, dtype):
405405
value : scalar
406406
dtype: string / dtype
407407
"""
408+
if isinstance(value, dict):
409+
return True
408410
if not is_scalar(value):
409411
# maybe always raise?
410412
# raise TypeError('"value" parameter must be a scalar or dict, but '

0 commit comments

Comments
 (0)