Skip to content

Commit 928fb7e

Browse files
audersonmroeschke
andauthored
PERF: use blk.dtype in where() & _setitem_frame() (#61014)
* use blk.dtype * Update pandas/core/generic.py Co-authored-by: Matthew Roeschke <[email protected]> * _setitem_frame(): use blk.dtype * add whatsnew 3.0.0 * add whatsnew 3.0.0 --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 5da9eb7 commit 928fb7e

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,9 @@ Performance improvements
614614
- Performance improvement in :meth:`RangeIndex.take` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57445`, :issue:`57752`)
615615
- Performance improvement in :func:`merge` if hash-join can be used (:issue:`57970`)
616616
- Performance improvement in :meth:`CategoricalDtype.update_dtype` when ``dtype`` is a :class:`CategoricalDtype` with non ``None`` categories and ordered (:issue:`59647`)
617+
- Performance improvement in :meth:`DataFrame.__getitem__` when ``key`` is a :class:`DataFrame` with many columns (:issue:`61010`)
617618
- Performance improvement in :meth:`DataFrame.astype` when converting to extension floating dtypes, e.g. "Float64" (:issue:`60066`)
619+
- Performance improvement in :meth:`DataFrame.where` when ``cond`` is a :class:`DataFrame` with many columns (:issue:`61010`)
618620
- Performance improvement in :meth:`to_hdf` avoid unnecessary reopenings of the HDF5 file to speedup data addition to files with a very large number of groups . (:issue:`58248`)
619621
- Performance improvement in ``DataFrameGroupBy.__len__`` and ``SeriesGroupBy.__len__`` (:issue:`57595`)
620622
- Performance improvement in indexing operations for string dtypes (:issue:`56997`)

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,7 @@ def _setitem_frame(self, key, value) -> None:
42814281
raise ValueError("Array conditional must be same shape as self")
42824282
key = self._constructor(key, **self._construct_axes_dict(), copy=False)
42834283

4284-
if key.size and not all(is_bool_dtype(dtype) for dtype in key.dtypes):
4284+
if key.size and not all(is_bool_dtype(blk.dtype) for blk in key._mgr.blocks):
42854285
raise TypeError(
42864286
"Must pass DataFrame or 2-d ndarray with boolean values only"
42874287
)

pandas/core/generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9732,9 +9732,9 @@ def _where(
97329732
if not is_bool_dtype(cond):
97339733
raise TypeError(msg.format(dtype=cond.dtype))
97349734
else:
9735-
for _dt in cond.dtypes:
9736-
if not is_bool_dtype(_dt):
9737-
raise TypeError(msg.format(dtype=_dt))
9735+
for block in cond._mgr.blocks:
9736+
if not is_bool_dtype(block.dtype):
9737+
raise TypeError(msg.format(dtype=block.dtype))
97389738
if cond._mgr.any_extension_types:
97399739
# GH51574: avoid object ndarray conversion later on
97409740
cond = cond._constructor(

0 commit comments

Comments
 (0)