Skip to content

Commit 6c0f653

Browse files
author
Anthony Speicher
committed
ENH: Add strict=True/False to zip calls in pandas/core/internals
1 parent f14f131 commit 6c0f653

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pandas/core/internals/blocks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def convert_dtypes(
564564
rbs.append(blk.copy(deep=False))
565565
continue
566566

567-
for dtype, b in zip(dtypes, sub_blks):
567+
for dtype, b in zip(dtypes, sub_blks, strict=True):
568568
rbs.append(b.astype(dtype=dtype, squeeze=b.ndim != 1))
569569
return rbs
570570

@@ -803,7 +803,7 @@ def replace_list(
803803
# Exclude anything that we know we won't contain
804804
pairs = [
805805
(x, y)
806-
for x, y in zip(src_list, dest_list)
806+
for x, y in zip(src_list, dest_list, strict=True)
807807
if (self._can_hold_element(x) or (self.dtype == "string" and is_re(x)))
808808
]
809809
if not pairs:
@@ -833,7 +833,7 @@ def replace_list(
833833
# references when we check again later
834834
rb = [self]
835835

836-
for i, ((src, dest), mask) in enumerate(zip(pairs, masks)):
836+
for i, ((src, dest), mask) in enumerate(zip(pairs, masks, strict=True)):
837837
new_rb: list[Block] = []
838838

839839
# GH-39338: _replace_coerce can split a block into
@@ -2117,7 +2117,7 @@ def _unstack(
21172117
BlockPlacement(place),
21182118
ndim=2,
21192119
)
2120-
for i, (indices, place) in enumerate(zip(new_values, new_placement))
2120+
for i, (indices, place) in enumerate(zip(new_values, new_placement, strict=True))
21212121
]
21222122
return blocks, mask
21232123

pandas/core/internals/construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def ndarray_to_mgr(
302302
for x in obj_columns
303303
]
304304
# don't convert (and copy) the objects if no type inference occurs
305-
if any(x is not y for x, y in zip(obj_columns, maybe_datetime)):
305+
if any(x is not y for x, y in zip(obj_columns, maybe_datetime, strict=True)):
306306
block_values = [
307307
new_block_2d(ensure_block_shape(dval, 2), placement=BlockPlacement(n))
308308
for n, dval in enumerate(maybe_datetime)

pandas/core/internals/managers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def equals(self, other: object) -> bool:
385385
self_axes, other_axes = self.axes, other.axes
386386
if len(self_axes) != len(other_axes):
387387
return False
388-
if not all(ax1.equals(ax2) for ax1, ax2 in zip(self_axes, other_axes)):
388+
if not all(ax1.equals(ax2) for ax1, ax2 in zip(self_axes, other_axes, strict=True)):
389389
return False
390390

391391
return self._equal_values(other)
@@ -989,7 +989,7 @@ def _slice_take_blocks_ax0(
989989
elif only_slice:
990990
# GH#33597 slice instead of take, so we get
991991
# views instead of copies
992-
for i, ml in zip(taker, mgr_locs):
992+
for i, ml in zip(taker, mgr_locs, strict=True):
993993
slc = slice(i, i + 1)
994994
bp = BlockPlacement(ml)
995995
nb = blk.getitem_block_columns(slc, new_mgr_locs=bp)
@@ -2411,12 +2411,12 @@ def _tuples_to_blocks_no_consolidate(tuples, refs) -> list[Block]:
24112411
new_block_2d(
24122412
ensure_block_shape(arr, ndim=2), placement=BlockPlacement(i), refs=ref
24132413
)
2414-
for ((i, arr), ref) in zip(tuples, refs)
2414+
for ((i, arr), ref) in zip(tuples, refs, strict=True)
24152415
]
24162416

24172417

24182418
def _stack_arrays(tuples, dtype: np.dtype):
2419-
placement, arrays = zip(*tuples)
2419+
placement, arrays = zip(*tuples, strict=True)
24202420

24212421
first = arrays[0]
24222422
shape = (len(arrays),) + first.shape

0 commit comments

Comments
 (0)