Skip to content

Commit

Permalink
REF (string): remove _str_na_value (pandas-dev#59515)
Browse files Browse the repository at this point in the history
* REF (string): remove _str_na_value

* mypy fixup
  • Loading branch information
jbrockmendel authored and jorisvandenbossche committed Oct 2, 2024
1 parent af28cd9 commit 5f4d3de
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 24 deletions.
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 @@ -838,12 +838,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 @@ -874,7 +868,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 @@ -279,10 +279,6 @@ def _data(self):
# ------------------------------------------------------------------------
# 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 @@ -270,7 +268,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 @@ -473,7 +471,7 @@ def _str_removesuffix(self, suffix: str) -> Series:

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

0 comments on commit 5f4d3de

Please sign in to comment.