-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): Add option to use PyArrow backed-extension arrays when …
…converting to pandas. Add "use_pyarrow_extension_array" argument to to pl.Series.to_pandas() and pl.DataFrame.to_pandas() as from Pandas 1.5.0, pandas Series and pandas DataFrame columns can be backed by PyArrow arrays. This allow zero copy operations and preservation of null values in Pandas dataframes. For big dataframe this can make the conversion to a pandas DataFrame almost for free, both in conversion time and memory usage: %time df_pd = df.pandas() CPU times: user 5.18 s, sys: 817 ms, total: 6 s Wall time: 5.12 s %time df_pd_pa = df.to_pandas(use_pyarrow_extension_array=True) CPU times: user 1.63 ms, sys: 71 µs, total: 1.7 ms Wall time: 1.57 ms Preservation of null values in pandas Series: >>> s1 = pl.Series("a", [1, 2, 3]) >>> s1.to_pandas() 0 1 1 2 2 3 Name: a, dtype: int64 >>> s1.to_pandas(use_pyarrow_extension_array=True) 0 1 1 2 2 3 Name: a, dtype: int64[pyarrow] >>> s2 = pl.Series("b", [1, 2, None, 4]) >>> s2.to_pandas() 0 1.0 1 2.0 2 NaN 3 4.0 Name: b, dtype: float64 >>> s2.to_pandas(use_pyarrow_extension_array=True) 0 1 1 2 2 <NA> 3 4 Name: b, dtype: int64[pyarrow]
- Loading branch information
Showing
4 changed files
with
191 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters