Skip to content

Commit

Permalink
FIX-modin-project#4060: Fix _to_pandas() dtypes for empty frames.
Browse files Browse the repository at this point in the history
Signed-off-by: mvashishtha <[email protected]>
  • Loading branch information
mvashishtha committed Jan 28, 2022
1 parent cafd213 commit 8312829
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/release_notes/release_notes-0.14.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Key Features and Updates
------------------------

* Stability and Bugfixes
*
* Fix to_pandas() dtypes for empty dataframes and series (0d7c273)
* Performance enhancements
*
* Benchmarking enhancements
Expand Down
4 changes: 3 additions & 1 deletion modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,9 @@ def to_pandas(self):
"""
df = self._partition_mgr_cls.to_pandas(self._partitions)
if df.empty:
df = pandas.DataFrame(columns=self.columns, index=self.index)
df = pandas.DataFrame(columns=self.columns, index=self.index).astype(
self.dtypes
)
else:
for axis in [0, 1]:
ErrorMessage.catch_bugs_and_request_email(
Expand Down
13 changes: 13 additions & 0 deletions modin/pandas/test/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from numpy.testing import assert_array_equal
from modin.utils import get_current_execution, to_pandas
from modin.test.test_utils import warns_that_defaulting_to_pandas
from pandas.testing import assert_frame_equal, assert_series_equal

from .utils import (
test_data_values,
Expand Down Expand Up @@ -765,3 +766,15 @@ def test_empty_dataframe():
def test_empty_series():
s = pd.Series([])
pd.to_numeric(s)


def test_to_pandas_empty_series():
pandas_series = pandas.Series([], dtype="bool")
modin_series = pd.Series(pandas_series)
assert_series_equal(pandas_series, modin_series._to_pandas(), check_dtype=True)


def test_to_pandas_empty_dataframe():
pandas_df = pandas.DataFrame([[]], dtype="bool")
modin_df = pd.DataFrame(pandas_df)
assert_frame_equal(pandas_df, modin_df._to_pandas(), check_dtype=True)

0 comments on commit 8312829

Please sign in to comment.