Skip to content

Commit d2bc509

Browse files
author
Roger Thomas
committed
Improve performance
1 parent 4f0f872 commit d2bc509

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

pandas/core/frame.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,30 +1846,29 @@ def _to_dict_helper(self, orient, into_c, into):
18461846
elif orient == "index":
18471847
if not self.index.is_unique:
18481848
raise ValueError("DataFrame index must be unique for orient='index'.")
1849+
columns = self.columns.tolist()
18491850
if object_dtype_cols:
18501851
is_object_dtype_by_index = [
18511852
col in object_dtype_cols for col in self.columns
18521853
]
18531854
return into_c(
18541855
(
18551856
t[0],
1856-
dict(
1857-
zip(
1858-
self.columns,
1859-
[
1860-
maybe_box_native(v)
1861-
if is_object_dtype_by_index[i]
1862-
else v
1863-
for i, v in enumerate(t[1:])
1864-
],
1865-
)
1866-
),
1857+
{
1858+
columns[i]: maybe_box_native(v)
1859+
if is_object_dtype_by_index[i]
1860+
else v
1861+
for i, v in enumerate(t[1:])
1862+
},
18671863
)
18681864
for t in self.itertuples(name=None)
18691865
)
18701866
else:
18711867
return into_c(
1872-
(t[0], dict(zip(self.columns, t[1:])))
1868+
(
1869+
t[0],
1870+
{columns[i]: v for i, v in enumerate(t[1:])},
1871+
)
18731872
for t in self.itertuples(name=None)
18741873
)
18751874
elif orient == "tight":

0 commit comments

Comments
 (0)