-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: standardize fill_value behavior across the API #15587
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -491,3 +491,27 @@ def pandas_dtype(dtype): | |
return dtype | ||
|
||
return np.dtype(dtype) | ||
|
||
|
||
def _is_fillable_value(value): | ||
pandas_ts_types = ('Timestamp', 'Period', 'Timedelta') | ||
pandas_block_types = ('Series', 'DataFrame') | ||
|
||
if any([isinstance(value, (list, dict)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the way to do this is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed these The former is valid in What I mean is that I think the implementation would be something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the idiom i gave us for using s validation function in a scalar or in each element of a list adapt 2 what u need |
||
callable(value), | ||
(not (isinstance(value, string_types) or | ||
isinstance(value, (int, float, complex, str, None.__class__)) or | ||
is_numeric_dtype(value) or | ||
is_datetime_or_timedelta_dtype(value) or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what you actually need though is to pass in 2 values at the top-level
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So when I call this method, would I need to do something like:
Beforehand? Not sure I grok this separate parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dtype must be passed in otherwise how do unknow is the filll_value is the right type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I've been following the
The same argument might apply for |
||
is_period_dtype(value) or | ||
type(value).__name__ in pandas_ts_types)), | ||
type(value).__name__ in pandas_block_types]): | ||
return False | ||
else: | ||
return True | ||
|
||
|
||
def validate_fill_value(value): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can just do this in one function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to separate creating the validity boolean from raising a |
||
if not _is_fillable_value(value): | ||
raise TypeError('"value" parameter must be a scalar, but ' | ||
'you passed a "{0}"'.format(type(value).__name__)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this should be in
pandas.types.missing