Skip to content

Commit 1e8555d

Browse files
committed
Finish up
1 parent 1d262ab commit 1e8555d

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def insert(self, loc: int, item) -> ArrowStringArray:
241241
return super().insert(loc, item)
242242

243243
def _convert_bool_result(self, values, na=lib.no_default, method_name=None):
244-
validate_na_arg(na, name="na", allow_no_default=True, allow_bool=True)
244+
validate_na_arg(na, name="na")
245245
if self.dtype.na_value is np.nan:
246246
if na is lib.no_default or isna(na):
247247
# NaN propagates as False

pandas/core/strings/object_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _str_contains(
144144
na=lib.no_default,
145145
regex: bool = True,
146146
):
147-
validate_na_arg(na, name="na", allow_no_default=True, allow_bool=True)
147+
validate_na_arg(na, name="na")
148148
if regex:
149149
if not case:
150150
flags |= re.IGNORECASE
@@ -161,12 +161,12 @@ def _str_contains(
161161
return self._str_map(f, na, dtype=np.dtype("bool"))
162162

163163
def _str_startswith(self, pat, na=lib.no_default):
164-
validate_na_arg(na, name="na", allow_no_default=True, allow_bool=True)
164+
validate_na_arg(na, name="na")
165165
f = lambda x: x.startswith(pat)
166166
return self._str_map(f, na_value=na, dtype=np.dtype(bool))
167167

168168
def _str_endswith(self, pat, na=lib.no_default):
169-
validate_na_arg(na, name="na", allow_no_default=True, allow_bool=True)
169+
validate_na_arg(na, name="na")
170170
f = lambda x: x.endswith(pat)
171171
return self._str_map(f, na_value=na, dtype=np.dtype(bool))
172172

pandas/tests/strings/test_find_replace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_contains_na_kwarg_for_nullable_string_dtype(
176176
values = Series(["a", "b", "c", "a", np.nan], dtype=nullable_string_dtype)
177177

178178
if na in [0, 3] and na is not False:
179-
msg = f"na must be a valid NA value; got {na}"
179+
msg = f"na must be an NA value, True, or False; got {na}"
180180
with pytest.raises(ValueError, match=msg):
181181
values.str.contains("a", na=na, regex=regex)
182182
else:
@@ -252,7 +252,7 @@ def test_contains_nan(any_string_dtype):
252252
expected = Series([True, True, True], dtype=expected_dtype)
253253
tm.assert_series_equal(result, expected)
254254

255-
msg = "na must be a valid NA value; got foo"
255+
msg = "na must be an NA value, True, or False; got foo"
256256
with pytest.raises(ValueError, match=msg):
257257
s.str.contains("foo", na="foo")
258258

@@ -339,7 +339,7 @@ def test_startswith_endswith_validate_na(any_string_dtype):
339339
["om", np.nan, "foo_nom", "nom", "bar_foo", np.nan, "foo"],
340340
dtype=any_string_dtype,
341341
)
342-
msg = "na must be a valid NA value; got baz"
342+
msg = "na must be an NA value, True, or False; got baz"
343343
with pytest.raises(ValueError, match=msg):
344344
ser.str.startswith("kapow", na="baz")
345345
with pytest.raises(ValueError, match=msg):

pandas/util/_validators.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ def validate_bool_kwarg(
270270
return value
271271

272272

273-
def validate_na_arg(
274-
value, name: str, allow_no_default: bool = False, allow_bool: bool = False
275-
):
273+
def validate_na_arg(value, name: str):
276274
"""
277275
Validate na arguments.
278276
@@ -282,23 +280,15 @@ def validate_na_arg(
282280
Value to validate.
283281
name : str
284282
Name of the argument, used to raise an informative error message.
285-
allow_no_default : bool, default False
286-
Whether to allow ``value`` to be ``lib.no_default``.
287-
allow_bool : bool, default False
288-
Whether to allow ``value`` to be an instance of bool.
289283
290284
Raises
291285
______
292286
ValueError
293287
When ``value`` is determined to be invalid.
294288
"""
295-
if allow_no_default and value is lib.no_default:
289+
if value is lib.no_default or isinstance(value, bool) or isna(value):
296290
return
297-
if allow_bool and isinstance(value, bool):
298-
return
299-
if isna(value):
300-
return
301-
raise ValueError(f"{name} must be a valid NA value; got {value}")
291+
raise ValueError(f"{name} must be an NA value, True, or False; got {value}")
302292

303293

304294
def validate_fillna_kwargs(value, method, validate_scalar_dict_value: bool = True):

0 commit comments

Comments
 (0)