Skip to content

Commit b133eef

Browse files
committed
Add fill validation methods.
1 parent 1a117fc commit b133eef

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: pandas/core/dtypes/common.py

+24
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,27 @@ def pandas_dtype(dtype):
739739
return dtype
740740

741741
return np.dtype(dtype)
742+
743+
744+
def _is_fillable_value(value):
745+
pandas_ts_types = ('Timestamp', 'Period', 'Timedelta')
746+
pandas_block_types = ('Series', 'DataFrame')
747+
748+
if any([isinstance(value, (list, dict)),
749+
callable(value),
750+
(not (isinstance(value, string_types) or
751+
isinstance(value, (int, float, complex, str, None.__class__)) or
752+
is_numeric_dtype(value) or
753+
is_datetime_or_timedelta_dtype(value) or
754+
is_period_dtype(value) or
755+
type(value).__name__ in pandas_ts_types) or
756+
type(value).__name__ in pandas_block_types)]):
757+
return False
758+
else:
759+
return True
760+
761+
762+
def validate_fill_value(value):
763+
if not _is_fillable_value(value):
764+
raise TypeError('"value" parameter must be a scalar, but '
765+
'you passed a "{0}"'.format(type(value).__name__))

0 commit comments

Comments
 (0)