Skip to content

Commit ce012eb

Browse files
mroeschkeraulcd
andauthored
apacheGH-45570: [Python] Allow Decimal32/64Array.to_pandas (apache#45571)
### Rationale for this change Enables converting `Decimal32Array` and `Decimal64Array` to pandas ### What changes are included in this PR? Adds `Type::DECIMAL32` and `Type::DECIMAL64` as convertible types to pandas ### Are these changes tested? Yes ### Are there any user-facing changes? Yes closes apache#45570 * GitHub Issue: apache#45570 Lead-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Co-authored-by: Raúl Cumplido <raulcumplido@gmail.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent f9283d0 commit ce012eb

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

python/pyarrow/src/arrow/python/arrow_to_pandas.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,8 @@ static Status GetPandasWriterType(const ChunkedArray& data, const PandasOptions&
21232123
case Type::STRUCT: // fall through
21242124
case Type::TIME32: // fall through
21252125
case Type::TIME64: // fall through
2126+
case Type::DECIMAL32: // fall through
2127+
case Type::DECIMAL64: // fall through
21262128
case Type::DECIMAL128: // fall through
21272129
case Type::DECIMAL256: // fall through
21282130
case Type::INTERVAL_MONTH_DAY_NANO: // fall through

python/pyarrow/tests/test_pandas.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,19 @@ def test_strided_objects(self, tmpdir):
20412041
df = pd.DataFrame.from_dict(data)
20422042
_check_pandas_roundtrip(df)
20432043

2044+
@pytest.mark.parametrize("typ", [
2045+
pa.decimal32,
2046+
pa.decimal64,
2047+
pa.decimal128,
2048+
pa.decimal256,
2049+
])
2050+
def test_decimal_array_to_pandas(self, typ):
2051+
data = [decimal.Decimal('3.14'), None]
2052+
arr = pa.array(data, type=typ(3, 2))
2053+
result = arr.to_pandas()
2054+
expected = pd.Series(data)
2055+
tm.assert_series_equal(result, expected)
2056+
20442057

20452058
class TestConvertListTypes:
20462059
"""

0 commit comments

Comments
 (0)