Skip to content

Commit 23926b5

Browse files
anthonyspeicherAnthony Speicher
andauthored
Zip Strict specification for pandas/core/internals (#62453)
Co-authored-by: Anthony Speicher <[email protected]>
1 parent 179258f commit 23926b5

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

pandas/core/internals/blocks.py

Lines changed: 6 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,9 @@ 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(
2121+
zip(new_values, new_placement, strict=True)
2122+
)
21212123
]
21222124
return blocks, mask
21232125

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ 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(
389+
ax1.equals(ax2) for ax1, ax2 in zip(self_axes, other_axes, strict=True)
390+
):
389391
return False
390392

391393
return self._equal_values(other)
@@ -989,7 +991,7 @@ def _slice_take_blocks_ax0(
989991
elif only_slice:
990992
# GH#33597 slice instead of take, so we get
991993
# views instead of copies
992-
for i, ml in zip(taker, mgr_locs):
994+
for i, ml in zip(taker, mgr_locs, strict=True):
993995
slc = slice(i, i + 1)
994996
bp = BlockPlacement(ml)
995997
nb = blk.getitem_block_columns(slc, new_mgr_locs=bp)
@@ -2411,12 +2413,12 @@ def _tuples_to_blocks_no_consolidate(tuples, refs) -> list[Block]:
24112413
new_block_2d(
24122414
ensure_block_shape(arr, ndim=2), placement=BlockPlacement(i), refs=ref
24132415
)
2414-
for ((i, arr), ref) in zip(tuples, refs)
2416+
for ((i, arr), ref) in zip(tuples, refs, strict=True)
24152417
]
24162418

24172419

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

24212423
first = arrays[0]
24222424
shape = (len(arrays),) + first.shape

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,6 @@ exclude = [
465465
"pandas/core/indexes/interval.py" = ["B905"]
466466
"pandas/core/indexes/multi.py" = ["B905"]
467467
"pandas/core/indexing.py" = ["B905"]
468-
"pandas/core/internals/blocks.py" = ["B905"]
469-
"pandas/core/internals/construction.py" = ["B905"]
470-
"pandas/core/internals/managers.py" = ["B905"]
471468
"pandas/core/methods/to_dict.py" = ["B905"]
472469
"pandas/core/reshape/concat.py" = ["B905"]
473470
"pandas/core/reshape/encoding.py" = ["B905"]

0 commit comments

Comments
 (0)