Skip to content

Commit d013e5a

Browse files
invain01pre-commit-ci[bot]
authored andcommitted
STY: Add strict=True in zip() in to_dict.py (pandas-dev#62589)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7f97edd commit d013e5a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pandas/core/methods/to_dict.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ def to_dict(
198198
if i in object_dtype_indices_as_set
199199
else list(map(maybe_box_native, v.to_numpy())),
200200
)
201-
for i, (box_na_value, (k, v)) in enumerate(zip(box_na_values, df.items()))
201+
for i, (box_na_value, (k, v)) in enumerate(
202+
zip(box_na_values, df.items(), strict=True)
203+
)
202204
)
203205

204206
elif orient == "split":
@@ -235,12 +237,13 @@ def to_dict(
235237
columns = df.columns.tolist()
236238
if are_all_object_dtype_cols:
237239
return [
238-
into_c(zip(columns, map(maybe_box_native, row)))
240+
into_c(zip(columns, map(maybe_box_native, row), strict=True))
239241
for row in df.itertuples(index=False, name=None)
240242
]
241243
else:
242244
data = [
243-
into_c(zip(columns, t)) for t in df.itertuples(index=False, name=None)
245+
into_c(zip(columns, t, strict=True))
246+
for t in df.itertuples(index=False, name=None)
244247
]
245248
if box_native_indices:
246249
object_dtype_indices_as_set = set(box_native_indices)
@@ -260,7 +263,7 @@ def to_dict(
260263
columns = df.columns.tolist()
261264
if are_all_object_dtype_cols:
262265
return into_c(
263-
(t[0], dict(zip(df.columns, map(maybe_box_native, t[1:]))))
266+
(t[0], dict(zip(df.columns, map(maybe_box_native, t[1:]), strict=True)))
264267
for t in df.itertuples(name=None)
265268
)
266269
elif box_native_indices:
@@ -272,14 +275,17 @@ def to_dict(
272275
column: maybe_box_native(v)
273276
if i in object_dtype_indices_as_set
274277
else v
275-
for i, (column, v) in enumerate(zip(columns, t[1:]))
278+
for i, (column, v) in enumerate(
279+
zip(columns, t[1:], strict=True)
280+
)
276281
},
277282
)
278283
for t in df.itertuples(name=None)
279284
)
280285
else:
281286
return into_c(
282-
(t[0], dict(zip(columns, t[1:]))) for t in df.itertuples(name=None)
287+
(t[0], dict(zip(columns, t[1:], strict=True)))
288+
for t in df.itertuples(name=None)
283289
)
284290

285291
else:

0 commit comments

Comments
 (0)