Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion leanframe/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ def __getitem__(self, key: str):
return leanframe.core.series.Series(self._data[key])

def to_pandas(self) -> pandas.DataFrame:
return self._data.to_pandas()
"""Convert the DataFrame to a pandas.DataFrame.

Where possible, pandas.ArrowDtype is used to avoid lossy conversions
from the database types to pandas.
"""
return self._data.to_pyarrow().to_pandas(
types_mapper=lambda type_: pandas.ArrowDtype(type_)
)
4 changes: 3 additions & 1 deletion leanframe/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ def name(self) -> str:

def to_pandas(self) -> pandas.Series:
"""Convert to a pandas Series."""
return self._data.to_pandas()
return self._data.to_pyarrow().to_pandas(
types_mapper=lambda type_: pandas.ArrowDtype(type_)
)
7 changes: 5 additions & 2 deletions tests/unit/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pandas
import pandas.testing
import pyarrow
import pytest

import leanframe
Expand All @@ -25,11 +26,13 @@
("series_pd",),
(
pytest.param(
pandas.Series([1, 2, 3]),
pandas.Series([1, 2, 3], dtype=pandas.ArrowDtype(pyarrow.int64())),
id="int64",
),
pytest.param(
pandas.Series([1.0, float("nan"), 3.0]),
pandas.Series(
[1.0, float("nan"), 3.0], dtype=pandas.ArrowDtype(pyarrow.float64())
),
id="float64",
),
),
Expand Down