Skip to content
Merged
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
31 changes: 25 additions & 6 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,20 @@ def test_astype_int(dtype, request):
tm.assert_extension_array_equal(result, expected)


def test_astype_float(any_float_allowed_nullable_dtype):
def test_astype_float(dtype, any_float_allowed_nullable_dtype, request):
# Don't compare arrays (37974)
ser = pd.Series(["1.1", pd.NA, "3.3"], dtype="string")

if dtype == "arrow_string":
if any_float_allowed_nullable_dtype in {"Float32", "Float64"}:
reason = "TypeError: Cannot interpret 'Float32Dtype()' as a data type"
else:
reason = (
"TypeError: float() argument must be a string or a number, not 'NAType'"
)
mark = pytest.mark.xfail(reason=reason)
request.node.add_marker(mark)

ser = pd.Series(["1.1", pd.NA, "3.3"], dtype=dtype)

result = ser.astype(any_float_allowed_nullable_dtype)
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_allowed_nullable_dtype)
Expand Down Expand Up @@ -436,17 +447,25 @@ def test_reduce_missing(skipna, dtype):
assert pd.isna(result)


def test_fillna_args():
def test_fillna_args(dtype, request):
# GH 37987

arr = pd.array(["a", pd.NA], dtype="string")
if dtype == "arrow_string":
reason = (
"AssertionError: Regex pattern \"Cannot set non-string value '1' into "
"a StringArray.\" does not match 'Scalar must be NA or str'"
)
mark = pytest.mark.xfail(reason=reason)
request.node.add_marker(mark)

arr = pd.array(["a", pd.NA], dtype=dtype)

res = arr.fillna(value="b")
expected = pd.array(["a", "b"], dtype="string")
expected = pd.array(["a", "b"], dtype=dtype)
tm.assert_extension_array_equal(res, expected)

res = arr.fillna(value=np.str_("b"))
expected = pd.array(["a", "b"], dtype="string")
expected = pd.array(["a", "b"], dtype=dtype)
tm.assert_extension_array_equal(res, expected)

msg = "Cannot set non-string value '1' into a StringArray."
Expand Down