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`) 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))