Skip to content

Commit cb83712

Browse files
authored
TST: Test dtype sparseDtype with specificd fill value (#50743)
1 parent 9e8a243 commit cb83712

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pandas/tests/arrays/sparse/test_astype.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
from pandas._libs.sparse import IntIndex
55

6-
from pandas import Timestamp
6+
from pandas import (
7+
DataFrame,
8+
Series,
9+
Timestamp,
10+
)
711
import pandas._testing as tm
812
from pandas.core.arrays.sparse import (
913
SparseArray,
@@ -131,3 +135,13 @@ def test_astype_dt64_to_int64(self):
131135
arr3 = SparseArray(values, dtype=dtype)
132136
result3 = arr3.astype("int64")
133137
tm.assert_numpy_array_equal(result3, expected)
138+
139+
140+
def test_dtype_sparse_with_fill_value_not_present_in_data():
141+
# GH 49987
142+
df = DataFrame([["a", 0], ["b", 1], ["b", 2]], columns=["A", "B"])
143+
result = df["A"].astype(SparseDtype("category", fill_value="c"))
144+
expected = Series(
145+
["a", "b", "b"], name="A", dtype=SparseDtype("object", fill_value="c")
146+
)
147+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)