Skip to content

Commit bced6fc

Browse files
REGR: fix period dtype <-> arrow roundtrip for pyarrow < 4 (pandas-dev#45524)
1 parent 753e6a6 commit bced6fc

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
lines changed

pandas/core/internals/api.py

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pandas.core.internals.blocks import (
2525
Block,
2626
DatetimeTZBlock,
27+
ExtensionBlock,
2728
check_ndim,
2829
ensure_block_shape,
2930
extract_pandas_array,
@@ -51,6 +52,12 @@ def make_block(
5152

5253
values, dtype = extract_pandas_array(values, dtype, ndim)
5354

55+
if klass is ExtensionBlock and is_period_dtype(values.dtype):
56+
# GH-44681 changed PeriodArray to be stored in the 2D
57+
# NDArrayBackedExtensionBlock instead of ExtensionBlock
58+
# -> still allow ExtensionBlock to be passed in this case for back compat
59+
klass = None
60+
5461
if klass is None:
5562
dtype = dtype or values.dtype
5663
klass = get_block_type(dtype)

pandas/tests/arrays/period/test_arrow_compat.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22

3-
from pandas.compat import pa_version_under4p0
4-
53
from pandas.core.dtypes.dtypes import PeriodDtype
64

75
import pandas as pd
@@ -71,9 +69,6 @@ def test_arrow_array_missing():
7169
assert result.storage.equals(expected)
7270

7371

74-
@pytest.mark.xfail(
75-
pa_version_under4p0, reason="pyarrow incorrectly uses pandas internals API"
76-
)
7772
def test_arrow_table_roundtrip():
7873
from pandas.core.arrays._arrow_utils import ArrowPeriodType
7974

@@ -93,9 +88,6 @@ def test_arrow_table_roundtrip():
9388
tm.assert_frame_equal(result, expected)
9489

9590

96-
@pytest.mark.xfail(
97-
pa_version_under4p0, reason="pyarrow incorrectly uses pandas internals API"
98-
)
9991
def test_arrow_load_from_zero_chunks():
10092
# GH-41040
10193

@@ -114,9 +106,6 @@ def test_arrow_load_from_zero_chunks():
114106
tm.assert_frame_equal(result, df)
115107

116108

117-
@pytest.mark.xfail(
118-
pa_version_under4p0, reason="pyarrow incorrectly uses pandas internals API"
119-
)
120109
def test_arrow_table_roundtrip_without_metadata():
121110
arr = PeriodArray([1, 2, 3], freq="H")
122111
arr[1] = pd.NaT

pandas/tests/io/test_feather.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import numpy as np
33
import pytest
44

5-
from pandas.compat.pyarrow import pa_version_under4p0
6-
75
import pandas as pd
86
import pandas._testing as tm
97

@@ -87,11 +85,7 @@ def test_basic(self):
8785
),
8886
}
8987
)
90-
if not pa_version_under4p0:
91-
# older pyarrow incorrectly uses pandas internal API, so
92-
# constructs invalid Block
93-
df["periods"] = pd.period_range("2013", freq="M", periods=3)
94-
88+
df["periods"] = pd.period_range("2013", freq="M", periods=3)
9589
df["timedeltas"] = pd.timedelta_range("1 day", periods=3)
9690
df["intervals"] = pd.interval_range(0, 3, 3)
9791

pandas/tests/io/test_parquet.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from pandas.compat.pyarrow import (
1717
pa_version_under2p0,
18-
pa_version_under4p0,
1918
pa_version_under5p0,
2019
pa_version_under6p0,
2120
)
@@ -652,13 +651,7 @@ def test_use_nullable_dtypes(self, engine, request):
652651
"object",
653652
"datetime64[ns, UTC]",
654653
"float",
655-
pytest.param(
656-
"period[D]",
657-
marks=pytest.mark.xfail(
658-
pa_version_under4p0,
659-
reason="pyarrow uses pandas internal API incorrectly",
660-
),
661-
),
654+
"period[D]",
662655
"Float64",
663656
"string",
664657
],
@@ -897,9 +890,6 @@ def test_pyarrow_backed_string_array(self, pa, string_storage):
897890
check_round_trip(df, pa, expected=df.astype(f"string[{string_storage}]"))
898891

899892
@td.skip_if_no("pyarrow")
900-
@pytest.mark.xfail(
901-
pa_version_under4p0, reason="pyarrow uses pandas internal API incorrectly"
902-
)
903893
def test_additional_extension_types(self, pa):
904894
# test additional ExtensionArrays that are supported through the
905895
# __arrow_array__ protocol + by defining a custom ExtensionType

0 commit comments

Comments
 (0)