Skip to content

Commit 66e465e

Browse files
authored
REF (string): remove _str_na_value (#59515)
* REF (string): remove _str_na_value * mypy fixup
1 parent 4409d42 commit 66e465e

File tree

4 files changed

+4
-24
lines changed

4 files changed

+4
-24
lines changed

pandas/core/arrays/numpy_.py

-4
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,3 @@ def _wrap_ndarray_result(self, result: np.ndarray):
557557

558558
return TimedeltaArray._simple_new(result, dtype=result.dtype)
559559
return type(self)(result)
560-
561-
# ------------------------------------------------------------------------
562-
# String methods interface
563-
_str_na_value = np.nan

pandas/core/arrays/string_.py

-10
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,6 @@ def _cmp_method(self, other, op):
848848

849849
_arith_method = _cmp_method
850850

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

858852
class StringArrayNumpySemantics(StringArray):
859853
_storage = "python"
@@ -884,7 +878,3 @@ def _from_backing_data(self, arr: np.ndarray) -> StringArrayNumpySemantics:
884878
# need to override NumpyExtensionArray._from_backing_data to ensure
885879
# we always preserve the dtype
886880
return NDArrayBacked._from_backing_data(self, arr)
887-
888-
# ------------------------------------------------------------------------
889-
# String methods interface
890-
_str_na_value = np.nan

pandas/core/arrays/string_arrow.py

-4
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ def astype(self, dtype, copy: bool = True):
275275
# ------------------------------------------------------------------------
276276
# String methods interface
277277

278-
# error: Incompatible types in assignment (expression has type "NAType",
279-
# base class "ObjectStringArrayMixin" defined the type as "float")
280-
_str_na_value = libmissing.NA # type: ignore[assignment]
281-
282278
_str_map = BaseStringArray._str_map
283279

284280
def _str_contains(

pandas/core/strings/object_array.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class ObjectStringArrayMixin(BaseStringArrayMethods):
3737
String Methods operating on object-dtype ndarrays.
3838
"""
3939

40-
_str_na_value = np.nan
41-
4240
def __len__(self) -> int:
4341
# For typing, _str_map relies on the object being sized.
4442
raise NotImplementedError
@@ -56,7 +54,7 @@ def _str_map(
5654
na_value : Scalar, optional
5755
The value to set for NA values. Might also be used for the
5856
fill value if the callable `f` raises an exception.
59-
This defaults to ``self._str_na_value`` which is ``np.nan``
57+
This defaults to ``self.dtype.na_value`` which is ``np.nan``
6058
for object-dtype and Categorical and ``pd.NA`` for StringArray.
6159
dtype : Dtype, optional
6260
The dtype of the result array.
@@ -66,7 +64,7 @@ def _str_map(
6664
if dtype is None:
6765
dtype = np.dtype("object")
6866
if na_value is None:
69-
na_value = self._str_na_value
67+
na_value = self.dtype.na_value # type: ignore[attr-defined]
7068

7169
if not len(self):
7270
return np.array([], dtype=dtype)
@@ -272,7 +270,7 @@ def f(x):
272270
return x.get(i)
273271
elif len(x) > i >= -len(x):
274272
return x[i]
275-
return self._str_na_value
273+
return self.dtype.na_value # type: ignore[attr-defined]
276274

277275
return self._str_map(f)
278276

@@ -466,7 +464,7 @@ def _str_removesuffix(self, suffix: str):
466464

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

471469
if not expand:
472470

0 commit comments

Comments
 (0)