Skip to content

REF (string): remove _str_na_value #59515

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

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,3 @@ def _wrap_ndarray_result(self, result: np.ndarray):

return TimedeltaArray._simple_new(result, dtype=result.dtype)
return type(self)(result)

# ------------------------------------------------------------------------
# String methods interface
_str_na_value = np.nan
10 changes: 0 additions & 10 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,6 @@ def _cmp_method(self, other, op):

_arith_method = _cmp_method

# ------------------------------------------------------------------------
# String methods interface
# error: Incompatible types in assignment (expression has type "NAType",
# base class "NumpyExtensionArray" defined the type as "float")
_str_na_value = libmissing.NA # type: ignore[assignment]


class StringArrayNumpySemantics(StringArray):
_storage = "python"
Expand Down Expand Up @@ -884,7 +878,3 @@ def _from_backing_data(self, arr: np.ndarray) -> StringArrayNumpySemantics:
# need to override NumpyExtensionArray._from_backing_data to ensure
# we always preserve the dtype
return NDArrayBacked._from_backing_data(self, arr)

# ------------------------------------------------------------------------
# String methods interface
_str_na_value = np.nan
4 changes: 0 additions & 4 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ def astype(self, dtype, copy: bool = True):
# ------------------------------------------------------------------------
# String methods interface

# error: Incompatible types in assignment (expression has type "NAType",
# base class "ObjectStringArrayMixin" defined the type as "float")
_str_na_value = libmissing.NA # type: ignore[assignment]

_str_map = BaseStringArray._str_map

def _str_contains(
Expand Down
10 changes: 4 additions & 6 deletions pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class ObjectStringArrayMixin(BaseStringArrayMethods):
String Methods operating on object-dtype ndarrays.
"""

_str_na_value = np.nan

def __len__(self) -> int:
# For typing, _str_map relies on the object being sized.
raise NotImplementedError
Expand All @@ -56,7 +54,7 @@ def _str_map(
na_value : Scalar, optional
The value to set for NA values. Might also be used for the
fill value if the callable `f` raises an exception.
This defaults to ``self._str_na_value`` which is ``np.nan``
This defaults to ``self.dtype.na_value`` which is ``np.nan``
for object-dtype and Categorical and ``pd.NA`` for StringArray.
dtype : Dtype, optional
The dtype of the result array.
Expand All @@ -66,7 +64,7 @@ def _str_map(
if dtype is None:
dtype = np.dtype("object")
if na_value is None:
na_value = self._str_na_value
na_value = self.dtype.na_value # type: ignore[attr-defined]

if not len(self):
return np.array([], dtype=dtype)
Expand Down Expand Up @@ -272,7 +270,7 @@ def f(x):
return x.get(i)
elif len(x) > i >= -len(x):
return x[i]
return self._str_na_value
return self.dtype.na_value # type: ignore[attr-defined]

return self._str_map(f)

Expand Down Expand Up @@ -466,7 +464,7 @@ def _str_removesuffix(self, suffix: str):

def _str_extract(self, pat: str, flags: int = 0, expand: bool = True):
regex = re.compile(pat, flags=flags)
na_value = self._str_na_value
na_value = self.dtype.na_value # type: ignore[attr-defined]

if not expand:

Expand Down