Skip to content

API: Change Series/DataFrame.other default to no_default instead of np.nan #49156

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 7 commits into from
Oct 18, 2022
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Other API changes
- 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`)
- 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`)
- 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`)
-
- 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`)

.. ---------------------------------------------------------------------------
.. _whatsnew_200.deprecations:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11998,7 +11998,7 @@ def mask(
def mask( # type: ignore[override]
self,
cond,
other=np.nan,
other=lib.no_default,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9871,6 +9871,9 @@ def where(
If other is callable, it is computed on the {klass} and
should return scalar or {klass}. The callable must not
change input {klass} (though pandas doesn't check it).
If not specified, entries will be filled with the corresponding
NULL value (``np.nan`` for numpy dtypes, ``pd.NA`` for extension
dtypes).
inplace : bool, default False
Whether to perform the operation in place on the data.
axis : int, default None
Expand Down Expand Up @@ -10072,7 +10075,7 @@ def mask(
def mask(
self: NDFrameT,
cond,
other=np.nan,
other=lib.no_default,
inplace: bool_t = False,
axis: Axis | None = None,
level: Level = None,
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,8 @@ def putmask(self, mask, new) -> list[Block]:
See Block.putmask.__doc__
"""
mask = extract_bool_array(mask)
if new is lib.no_default:
new = self.fill_value

values = self.values
if values.ndim == 2:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6205,7 +6205,7 @@ def mask(
def mask( # type: ignore[override]
self,
cond,
other=np.nan,
other=lib.no_default,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,17 +856,6 @@ def test_searchsorted(self, data_for_sorting, as_series, request):
)
super().test_searchsorted(data_for_sorting, as_series)

def test_where_series(self, data, na_value, as_frame, request):
pa_dtype = data.dtype.pyarrow_dtype
if pa.types.is_temporal(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"Unsupported cast from double to {pa_dtype}",
)
)
super().test_where_series(data, na_value, as_frame)

def test_basic_equals(self, data):
# https://github.com/pandas-dev/pandas/issues/34660
assert pd.Series(data).equals(pd.Series(data))
Expand Down