Skip to content

Commit 4f58c8a

Browse files
committed
Remove deprecation of fill_value for SparseDType[bool](pandas-dev#44955)
1 parent 2669c97 commit 4f58c8a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

asv_bench/benchmarks/sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def setup(self, fill_value):
223223
fv_inds = np.unique(
224224
np.random.randint(low=0, high=N - 1, size=int(N * d), dtype=np.int32)
225225
)
226-
b_arr[fv_inds] = not fill_value
226+
b_arr[fv_inds] = True if pd.isna(fill_value) else not fill_value
227227
self.sp_b_arr = SparseArray(b_arr, dtype=np.bool8, fill_value=fill_value)
228228

229229
def time_mask(self, fill_value):

doc/source/whatsnew/v1.4.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ Other Deprecations
545545
- A deprecation warning is now shown for :meth:`DataFrame.to_latex` indicating the arguments signature may change and emulate more the arguments to :meth:`.Styler.to_latex` in future versions (:issue:`44411`)
546546
- Deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`)
547547
- Deprecated :meth:`Index.__getitem__` with a bool key; use ``index.values[key]`` to get the old behavior (:issue:`44051`)
548-
- Deprecated direct passing non boolean or non nan value to ``fill_value`` for :class:`SparseDType` when dtype is bool type (:pull:`44955`)
549548
-
550549

551550
.. ---------------------------------------------------------------------------

pandas/core/arrays/sparse/dtype.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
)
2525
from pandas.core.dtypes.cast import astype_nansafe
2626
from pandas.core.dtypes.common import (
27-
is_bool,
2827
is_bool_dtype,
2928
is_object_dtype,
3029
is_scalar,
@@ -154,13 +153,18 @@ def _check_fill_value(self):
154153
raise ValueError(
155154
f"fill_value must be a scalar. Got {self._fill_value} instead"
156155
)
157-
if self._is_boolean and not (
158-
is_bool(self._fill_value) or isna(self._fill_value)
159-
):
160-
raise ValueError(
161-
"fill_value must be True, False or nan "
162-
f"for boolean type. Got {self._fill_value} instead"
163-
)
156+
# TODO: Right now we can use Sparse boolean array
157+
# with any fill_value. Here was an attempt
158+
# to allow only 3 value: True, False or nan
159+
# but plenty test has failed.
160+
# see pull 44955
161+
# if self._is_boolean and not (
162+
# is_bool(self._fill_value) or isna(self._fill_value)
163+
# ):
164+
# raise ValueError(
165+
# "fill_value must be True, False or nan "
166+
# f"for boolean type. Got {self._fill_value} instead"
167+
# )
164168

165169
@property
166170
def _is_na_fill_value(self) -> bool:

pandas/tests/arrays/sparse/test_array.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,11 @@ def test_set_fill_value(self):
625625
assert arr.fill_value
626626

627627
# coerces to bool
628-
msg = "fill_value must be True, False or nan"
629-
with pytest.raises(ValueError, match=msg):
630-
arr.fill_value = 0
628+
# XXX: we can construct an sparse array of bool
629+
# type and use as fill_value any value
630+
# msg = "fill_value must be True, False or nan"
631+
# with pytest.raises(ValueError, match=msg):
632+
# arr.fill_value = 0
631633

632634
# msg = "unable to set fill_value nan to bool dtype"
633635
# with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)