Skip to content

TST: Test dtype sparseDtype with specificd fill value #50743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
16 changes: 15 additions & 1 deletion pandas/tests/arrays/sparse/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

from pandas._libs.sparse import IntIndex

from pandas import Timestamp
from pandas import (
DataFrame,
Series,
Timestamp,
)
import pandas._testing as tm
from pandas.core.arrays.sparse import (
SparseArray,
Expand Down Expand Up @@ -131,3 +135,13 @@ def test_astype_dt64_to_int64(self):
arr3 = SparseArray(values, dtype=dtype)
result3 = arr3.astype("int64")
tm.assert_numpy_array_equal(result3, expected)


def test_dtype_sparse_with_fill_value_not_present_in_data():
# GH 49987
df = DataFrame([["a", 0], ["b", 1], ["b", 2]], columns=["A", "B"])
result = df["A"].astype(SparseDtype("category", fill_value="c"))
expected = Series(
["a", "b", "b"], name="A", dtype=SparseDtype("object", fill_value="c")
)
tm.assert_series_equal(result, expected)