Skip to content

Commit e17c67c

Browse files
mroeschkenoatamir
authored andcommitted
API: Change Series/DataFrame.other default to no_default instead of np.nan (pandas-dev#49156)
1 parent dc8b920 commit e17c67c

File tree

6 files changed

+9
-15
lines changed

6 files changed

+9
-15
lines changed

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Other API changes
126126
- Passing data with dtype of "timedelta64[s]", "timedelta64[ms]", or "timedelta64[us]" to :class:`TimedeltaIndex`, :class:`Series`, or :class:`DataFrame` constructors will now retain that dtype instead of casting to "timedelta64[ns]"; timedelta64 data with lower resolution will be cast to the lowest supported resolution "timedelta64[s]" (:issue:`49014`)
127127
- Passing ``dtype`` of "timedelta64[s]", "timedelta64[ms]", or "timedelta64[us]" to :class:`TimedeltaIndex`, :class:`Series`, or :class:`DataFrame` constructors will now retain that dtype instead of casting to "timedelta64[ns]"; passing a dtype with lower resolution for :class:`Series` or :class:`DataFrame` will be cast to the lowest supported resolution "timedelta64[s]" (:issue:`49014`)
128128
- Passing a ``np.datetime64`` object with non-nanosecond resolution to :class:`Timestamp` will retain the input resolution if it is "s", "ms", or "ns"; otherwise it will be cast to the closest supported resolution (:issue:`49008`)
129-
-
129+
- The ``other`` argument in :meth:`DataFrame.mask` and :meth:`Series.mask` now defaults to ``no_default`` instead of ``np.nan`` consistent with :meth:`DataFrame.where` and :meth:`Series.where`. Entries will be filled with the corresponding NULL value (``np.nan`` for numpy dtypes, ``pd.NA`` for extension dtypes). (:issue:`49111`)
130130

131131
.. ---------------------------------------------------------------------------
132132
.. _whatsnew_200.deprecations:

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11998,7 +11998,7 @@ def mask(
1199811998
def mask( # type: ignore[override]
1199911999
self,
1200012000
cond,
12001-
other=np.nan,
12001+
other=lib.no_default,
1200212002
inplace: bool = False,
1200312003
axis: Axis | None = None,
1200412004
level: Level = None,

pandas/core/generic.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -9871,6 +9871,9 @@ def where(
98719871
If other is callable, it is computed on the {klass} and
98729872
should return scalar or {klass}. The callable must not
98739873
change input {klass} (though pandas doesn't check it).
9874+
If not specified, entries will be filled with the corresponding
9875+
NULL value (``np.nan`` for numpy dtypes, ``pd.NA`` for extension
9876+
dtypes).
98749877
inplace : bool, default False
98759878
Whether to perform the operation in place on the data.
98769879
axis : int, default None
@@ -10072,7 +10075,7 @@ def mask(
1007210075
def mask(
1007310076
self: NDFrameT,
1007410077
cond,
10075-
other=np.nan,
10078+
other=lib.no_default,
1007610079
inplace: bool_t = False,
1007710080
axis: Axis | None = None,
1007810081
level: Level = None,

pandas/core/internals/blocks.py

+2
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,8 @@ def putmask(self, mask, new) -> list[Block]:
15131513
See Block.putmask.__doc__
15141514
"""
15151515
mask = extract_bool_array(mask)
1516+
if new is lib.no_default:
1517+
new = self.fill_value
15161518

15171519
values = self.values
15181520
if values.ndim == 2:

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6205,7 +6205,7 @@ def mask(
62056205
def mask( # type: ignore[override]
62066206
self,
62076207
cond,
6208-
other=np.nan,
6208+
other=lib.no_default,
62096209
inplace: bool = False,
62106210
axis: Axis | None = None,
62116211
level: Level = None,

pandas/tests/extension/test_arrow.py

-11
Original file line numberDiff line numberDiff line change
@@ -856,17 +856,6 @@ def test_searchsorted(self, data_for_sorting, as_series, request):
856856
)
857857
super().test_searchsorted(data_for_sorting, as_series)
858858

859-
def test_where_series(self, data, na_value, as_frame, request):
860-
pa_dtype = data.dtype.pyarrow_dtype
861-
if pa.types.is_temporal(pa_dtype):
862-
request.node.add_marker(
863-
pytest.mark.xfail(
864-
raises=pa.ArrowNotImplementedError,
865-
reason=f"Unsupported cast from double to {pa_dtype}",
866-
)
867-
)
868-
super().test_where_series(data, na_value, as_frame)
869-
870859
def test_basic_equals(self, data):
871860
# https://github.com/pandas-dev/pandas/issues/34660
872861
assert pd.Series(data).equals(pd.Series(data))

0 commit comments

Comments
 (0)