This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new ce012eb2e8 GH-45570: [Python] Allow Decimal32/64Array.to_pandas 
(#45571)
ce012eb2e8 is described below

commit ce012eb2e8bb36950d8876c1b9f0d5ccdd0e025e
Author: Matthew Roeschke <[email protected]>
AuthorDate: Thu Feb 20 06:14:36 2025 -0800

    GH-45570: [Python] Allow Decimal32/64Array.to_pandas (#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 https://github.com/apache/arrow/issues/45570
    
    * GitHub Issue: #45570
    
    Lead-authored-by: Matthew Roeschke 
<[email protected]>
    Co-authored-by: Raúl Cumplido <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 python/pyarrow/src/arrow/python/arrow_to_pandas.cc |  2 ++
 python/pyarrow/tests/test_pandas.py                | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc 
b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc
index a0f1d5bbbe..335fbbdd0f 100644
--- a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc
+++ b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc
@@ -2123,6 +2123,8 @@ static Status GetPandasWriterType(const ChunkedArray& 
data, const PandasOptions&
     case Type::STRUCT:                   // fall through
     case Type::TIME32:                   // fall through
     case Type::TIME64:                   // fall through
+    case Type::DECIMAL32:                // fall through
+    case Type::DECIMAL64:                // fall through
     case Type::DECIMAL128:               // fall through
     case Type::DECIMAL256:               // fall through
     case Type::INTERVAL_MONTH_DAY_NANO:  // fall through
diff --git a/python/pyarrow/tests/test_pandas.py 
b/python/pyarrow/tests/test_pandas.py
index f356874c57..54b89b45f2 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -2041,6 +2041,19 @@ class TestConvertDecimalTypes:
         df = pd.DataFrame.from_dict(data)
         _check_pandas_roundtrip(df)
 
+    @pytest.mark.parametrize("typ", [
+        pa.decimal32,
+        pa.decimal64,
+        pa.decimal128,
+        pa.decimal256,
+    ])
+    def test_decimal_array_to_pandas(self, typ):
+        data = [decimal.Decimal('3.14'), None]
+        arr = pa.array(data, type=typ(3, 2))
+        result = arr.to_pandas()
+        expected = pd.Series(data)
+        tm.assert_series_equal(result, expected)
+
 
 class TestConvertListTypes:
     """

Reply via email to