Skip to content

Commit e61c628

Browse files
jbrockmendeljorisvandenbossche
authored andcommitted
REF (string): remove _str_na_value (#59515)
* REF (string): remove _str_na_value * mypy fixup
1 parent b1ee91f commit e61c628

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
@@ -838,12 +838,6 @@ def _cmp_method(self, other, op):
838838

839839
_arith_method = _cmp_method
840840

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

848842
class StringArrayNumpySemantics(StringArray):
849843
_storage = "python"
@@ -874,7 +868,3 @@ def _from_backing_data(self, arr: np.ndarray) -> StringArrayNumpySemantics:
874868
# need to override NumpyExtensionArray._from_backing_data to ensure
875869
# we always preserve the dtype
876870
return NDArrayBacked._from_backing_data(self, arr)
877-
878-
# ------------------------------------------------------------------------
879-
# String methods interface
880-
_str_na_value = np.nan

pandas/core/arrays/string_arrow.py

-4
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ def _data(self):
279279
# ------------------------------------------------------------------------
280280
# String methods interface
281281

282-
# error: Incompatible types in assignment (expression has type "NAType",
283-
# base class "ObjectStringArrayMixin" defined the type as "float")
284-
_str_na_value = libmissing.NA # type: ignore[assignment]
285-
286282
_str_map = BaseStringArray._str_map
287283

288284
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)
@@ -270,7 +268,7 @@ def f(x):
270268
return x.get(i)
271269
elif len(x) > i >= -len(x):
272270
return x[i]
273-
return self._str_na_value
271+
return self.dtype.na_value # type: ignore[attr-defined]
274272

275273
return self._str_map(f)
276274

@@ -473,7 +471,7 @@ def _str_removesuffix(self, suffix: str) -> Series:
473471

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

478476
if not expand:
479477

0 commit comments

Comments
 (0)