Skip to content

Commit f051112

Browse files
committed
Add fill validation methods.
1 parent 075eca1 commit f051112

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/core/dtypes/common.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,27 @@ def pandas_dtype(dtype):
804804
raise TypeError('dtype {0} not understood'.format(dtype))
805805

806806
return npdtype
807+
808+
809+
def _is_fillable_value(value):
810+
pandas_ts_types = ('Timestamp', 'Period', 'Timedelta')
811+
pandas_block_types = ('Series', 'DataFrame')
812+
813+
if any([isinstance(value, (list, dict)),
814+
callable(value),
815+
(not (isinstance(value, string_types) or
816+
isinstance(value, (int, float, complex, str, None.__class__)) or
817+
is_numeric_dtype(value) or
818+
is_datetime_or_timedelta_dtype(value) or
819+
is_period_dtype(value) or
820+
type(value).__name__ in pandas_ts_types) or
821+
type(value).__name__ in pandas_block_types)]):
822+
return False
823+
else:
824+
return True
825+
826+
827+
def validate_fill_value(value):
828+
if not _is_fillable_value(value):
829+
raise TypeError('"value" parameter must be a scalar, but '
830+
'you passed a "{0}"'.format(type(value).__name__))

0 commit comments

Comments
 (0)