-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN/TST: delegate StringArray.fillna() to parent class + add tests #37987
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
Changes from 16 commits
e6a3f40
0a85704
4814614
7051e97
df8e185
43a6646
616a6c7
a43de61
f6eff15
24cb928
9b2f918
a014784
02ff905
b658791
135f55a
ef1f800
719d3cd
f1489c7
0e84df8
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 |
---|---|---|
|
@@ -254,19 +254,8 @@ def _values_for_factorize(self): | |
arr[mask] = -1 | ||
return arr, -1 | ||
|
||
def __setitem__(self, key, value): | ||
value = extract_array(value, extract_numpy=True) | ||
if isinstance(value, type(self)): | ||
# extract_array doesn't extract PandasArray subclasses | ||
value = value._ndarray | ||
|
||
key = check_array_indexer(self, key) | ||
scalar_key = lib.is_scalar(key) | ||
def _validate_setitem_value(self, value): | ||
scalar_value = lib.is_scalar(value) | ||
if scalar_key and not scalar_value: | ||
raise ValueError("setting an array element with a sequence.") | ||
|
||
# validate new items | ||
if scalar_value: | ||
if isna(value): | ||
value = StringDtype.na_value | ||
|
@@ -279,11 +268,27 @@ def __setitem__(self, key, value): | |
value = np.asarray(value, dtype=object) | ||
if len(value) and not lib.is_string_array(value, skipna=True): | ||
raise ValueError("Must provide strings.") | ||
return value | ||
|
||
def __setitem__(self, key, value): | ||
value = extract_array(value, extract_numpy=True) | ||
if isinstance(value, type(self)): | ||
# extract_array doesn't extract PandasArray subclasses | ||
value = value._ndarray | ||
|
||
key = check_array_indexer(self, key) | ||
scalar_key = lib.is_scalar(key) | ||
scalar_value = lib.is_scalar(value) | ||
if scalar_key and not scalar_value: | ||
raise ValueError("setting an array element with a sequence.") | ||
|
||
value = self._validate_setitem_value(value) | ||
|
||
super().__setitem__(key, value) | ||
|
||
def fillna(self, value=None, method=None, limit=None): | ||
# TODO: validate dtype | ||
if value is not None: | ||
value = self._validate_setitem_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. This is actually not needed, as the setitem under the hood of fillna already calls it. So calling it here as well means we validate the value twice. 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. right, reverted all the changes here |
||
return super().fillna(value, method, limit) | ||
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. does this method need to be overriden here at all? 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. it doesn't 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. pushed that now |
||
|
||
def astype(self, dtype, copy=True): | ||
|
Uh oh!
There was an error while loading. Please reload this page.