From 10e3d7e96e14dfd0a96c919cacc369fb5137ad52 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 3 Sep 2022 21:25:58 +0200 Subject: [PATCH 1/2] DOC: Clarify that objects dtype takes precedence in where --- pandas/core/generic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 32d4ac24a1d53..a5a75e0a3f7fb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9897,6 +9897,9 @@ def where( For further details and examples see the ``{name}`` documentation in :ref:`indexing `. + The dtype of the object takes precedence. The fill value is casted to + the objects dtype, if this can be done losslessly. + Examples -------- >>> s = pd.Series(range(5)) From f676573afa91cedaf30cd982337fba1347c88588 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 6 Sep 2022 23:17:38 +0200 Subject: [PATCH 2/2] Add whatsnew --- doc/source/whatsnew/v1.5.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 8671b73526f80..4a0619b7beb5b 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -308,6 +308,7 @@ Other enhancements - Implemented a complex-dtype :class:`Index`, passing a complex-dtype array-like to ``pd.Index`` will now retain complex dtype instead of casting to ``object`` (:issue:`45845`) - :class:`Series` and :class:`DataFrame` with :class:`IntegerDtype` now supports bitwise operations (:issue:`34463`) - Add ``milliseconds`` field support for :class:`.DateOffset` (:issue:`43371`) +- :meth:`DataFrame.where` tries to maintain dtype of :class:`DataFrame` if fill value can be cast without loss of precision (:issue:`45582`) - :meth:`DataFrame.reset_index` now accepts a ``names`` argument which renames the index names (:issue:`6878`) - :func:`concat` now raises when ``levels`` is given but ``keys`` is None (:issue:`46653`) - :func:`concat` now raises when ``levels`` contains duplicate values (:issue:`46653`)