Skip to content

BUG: Return Float64 for read_parquet(use_nullable_dtypes=True) #47619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2022
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ I/O
- Bug in :func:`read_sas` with RLE-compressed SAS7BDAT files that contain 0x40 control bytes (:issue:`31243`)
- Bug in :func:`read_sas` that scrambled column names (:issue:`31243`)
- Bug in :func:`read_sas` with RLE-compressed SAS7BDAT files that contain 0x00 control bytes (:issue:`47099`)
-
- Bug in :func:`read_parquet` with ``use_nullable_dtypes=True`` where ``float64`` dtype was returned instead of nullable ``Float64`` dtype (:issue:`45694`)

Period
^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def read(
self.api.uint64(): pd.UInt64Dtype(),
self.api.bool_(): pd.BooleanDtype(),
self.api.string(): pd.StringDtype(),
self.api.float32(): pd.Float32Dtype(),
self.api.float64(): pd.Float64Dtype(),
}
to_pandas_kwargs["types_mapper"] = mapping.get
manager = get_option("mode.data_manager")
Expand Down
17 changes: 16 additions & 1 deletion pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ def test_use_nullable_dtypes(self, engine, request):
"d": pyarrow.array([True, False, True, None]),
# Test that nullable dtypes used even in absence of nulls
"e": pyarrow.array([1, 2, 3, 4], "int64"),
# GH 45694
"f": pyarrow.array([1.0, 2.0, 3.0, None], "float32"),
"g": pyarrow.array([1.0, 2.0, 3.0, None], "float64"),
}
)
with tm.ensure_clean() as path:
Expand All @@ -642,6 +645,8 @@ def test_use_nullable_dtypes(self, engine, request):
"c": pd.array(["a", "b", "c", None], dtype="string"),
"d": pd.array([True, False, True, None], dtype="boolean"),
"e": pd.array([1, 2, 3, 4], dtype="Int64"),
"f": pd.array([1.0, 2.0, 3.0, None], dtype="Float32"),
"g": pd.array([1.0, 2.0, 3.0, None], dtype="Float64"),
}
)
if engine == "fastparquet":
Expand Down Expand Up @@ -672,7 +677,17 @@ def test_read_empty_array(self, pa, dtype):
"value": pd.array([], dtype=dtype),
}
)
check_round_trip(df, pa, read_kwargs={"use_nullable_dtypes": True})
# GH 45694
expected = None
if dtype == "float":
expected = pd.DataFrame(
{
"value": pd.array([], dtype="Float64"),
}
)
check_round_trip(
df, pa, read_kwargs={"use_nullable_dtypes": True}, expected=expected
)


@pytest.mark.filterwarnings("ignore:CategoricalBlock is deprecated:DeprecationWarning")
Expand Down