Skip to content

Commit

Permalink
feat(python): 10% speedup for to_dicts method (#6415)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 25, 2023
1 parent a0c9bab commit fe22509
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,13 +1830,8 @@ def to_dicts(self) -> list[dict[str, Any]]:
[{'foo': 1, 'bar': 4}, {'foo': 2, 'bar': 5}, {'foo': 3, 'bar': 6}]
"""
pydf = self._df
names = self.columns

return [
{k: v for k, v in zip(names, pydf.row_tuple(i))}
for i in range(0, self.height)
]
dict_, zip_, columns = dict, zip, self.columns
return [dict_(zip_(columns, row)) for row in self.iterrows()]

def to_numpy(self) -> np.ndarray[Any, Any]:
"""
Expand Down

0 comments on commit fe22509

Please sign in to comment.