Skip to content

Commit 4226f42

Browse files
Backport PR #48380 on branch 1.5.x (DOC: Clarify that objects dtype takes precedence in where) (#48445)
* Backport PR #48380: DOC: Clarify that objects dtype takes precedence in where * Update generic.py Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 3fd62c4 commit 4226f42

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Other enhancements
308308
- 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`)
309309
- :class:`Series` and :class:`DataFrame` with :class:`IntegerDtype` now supports bitwise operations (:issue:`34463`)
310310
- Add ``milliseconds`` field support for :class:`.DateOffset` (:issue:`43371`)
311+
- :meth:`DataFrame.where` tries to maintain dtype of :class:`DataFrame` if fill value can be cast without loss of precision (:issue:`45582`)
311312
- :meth:`DataFrame.reset_index` now accepts a ``names`` argument which renames the index names (:issue:`6878`)
312313
- :func:`concat` now raises when ``levels`` is given but ``keys`` is None (:issue:`46653`)
313314
- :func:`concat` now raises when ``levels`` contains duplicate values (:issue:`46653`)

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -9876,6 +9876,9 @@ def where(
98769876
For further details and examples see the ``{name}`` documentation in
98779877
:ref:`indexing <indexing.where_mask>`.
98789878
9879+
The dtype of the object takes precedence. The fill value is casted to
9880+
the object's dtype, if this can be done losslessly.
9881+
98799882
Examples
98809883
--------
98819884
>>> s = pd.Series(range(5))

0 commit comments

Comments
 (0)