Skip to content

Commit 8c128a9

Browse files
committed
simplify method signature
1 parent 38f73e7 commit 8c128a9

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

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,
@@ -3383,11 +3382,17 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
33833382

33843383
@Appender(_shared_docs['fillna'] % _shared_doc_kwargs)
33853384
def fillna(self, value=None, method=None, axis=None, inplace=False,
3386-
limit=None, downcast=None, errors=None):
3385+
limit=None, downcast=None, errors='coerce'):
33873386
inplace = validate_bool_kwarg(inplace, 'inplace')
33883387

3389-
if not missing.maybe_fill(self, value, errors):
3390-
return self
3388+
try:
3389+
missing.validate_fill_value(self, value)
3390+
except TypeError:
3391+
if errors == 'ignore':
3392+
return
3393+
elif errors == 'raise':
3394+
raise
3395+
# if errors == 'coerce' continue
33913396

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

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

@@ -625,7 +624,7 @@ def fill_zeros(result, x, y, name, fill):
625624
return result
626625

627626

628-
def maybe_fill(obj, value, errors):
627+
def validate_fill_value(obj, value):
629628
"""
630629
631630
Fillna error coercion routine.
@@ -659,16 +658,8 @@ def maybe_fill(obj, value, errors):
659658
fillna error coercion routine, returns whether or not to continue.
660659
"""
661660
if isinstance(obj, ABCSeries):
662-
if errors is None or errors == 'coerce':
663-
return True
664-
else:
665-
if not is_valid_fill_value(value, obj.dtype):
666-
if errors == 'raise':
667-
raise TypeError('"value" parameter must be compatible '
668-
'with the {0} dtype, but you passed a '
669-
'"{1}"'.format(obj.dtype,
670-
type(value).__name__))
671-
else: # errors == 'ignore'; short-circuit
672-
return False
673-
else:
674-
return True
661+
if not is_valid_fill_value(value, obj.dtype):
662+
raise TypeError('"value" parameter must be compatible '
663+
'with the {0} dtype, but you passed a '
664+
'"{1}"'.format(obj.dtype,
665+
type(value).__name__))

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)