You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/11/22 22:22:24 UTC

[arrow] branch master updated: ARROW-1845: [Python] Expose Decimal128Type

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9b2dc77  ARROW-1845: [Python] Expose Decimal128Type
9b2dc77 is described below

commit 9b2dc77a4d95c7415edd5be087a5abafc5a7f64c
Author: Uwe L. Korn <uw...@xhochy.com>
AuthorDate: Wed Nov 22 17:22:19 2017 -0500

    ARROW-1845: [Python] Expose Decimal128Type
    
    Author: Uwe L. Korn <uw...@xhochy.com>
    Author: Wes McKinney <we...@twosigma.com>
    
    Closes #1348 from xhochy/ARROW-1845 and squashes the following commits:
    
    98514320 [Wes McKinney] Fix API page in Python docs for decimal->decimal128
    5fade1f5 [Uwe L. Korn] ARROW-1845: [Python] Expose Decimal128Type
---
 python/doc/source/api.rst                    |  2 +-
 python/pyarrow/__init__.py                   |  2 +-
 python/pyarrow/includes/libarrow.pxd         |  4 ++--
 python/pyarrow/lib.pxd                       |  4 ++--
 python/pyarrow/pandas_compat.py              |  2 +-
 python/pyarrow/public-api.pxi                |  2 +-
 python/pyarrow/tests/test_array.py           |  2 +-
 python/pyarrow/tests/test_convert_builtin.py | 12 ++++++------
 python/pyarrow/tests/test_convert_pandas.py  |  6 +++---
 python/pyarrow/tests/test_schema.py          |  2 +-
 python/pyarrow/tests/test_types.py           |  2 +-
 python/pyarrow/types.pxi                     | 18 +++++++++---------
 12 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/python/doc/source/api.rst b/python/doc/source/api.rst
index 8f2f23d..fb2a286 100644
--- a/python/doc/source/api.rst
+++ b/python/doc/source/api.rst
@@ -50,7 +50,7 @@ Type and Schema Factory Functions
    date64
    binary
    string
-   decimal
+   decimal128
    list_
    struct
    dictionary
diff --git a/python/pyarrow/__init__.py b/python/pyarrow/__init__.py
index c8ded2d..c4db36e 100644
--- a/python/pyarrow/__init__.py
+++ b/python/pyarrow/__init__.py
@@ -35,7 +35,7 @@ from pyarrow.lib import (null, bool_,
                          uint8, uint16, uint32, uint64,
                          time32, time64, timestamp, date32, date64,
                          float16, float32, float64,
-                         binary, string, decimal,
+                         binary, string, decimal128,
                          list_, struct, union, dictionary, field,
                          type_for_alias,
                          DataType, NAType,
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index 73e34c7..f1f5938 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -209,10 +209,10 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         int byte_width()
         int bit_width()
 
-    cdef cppclass CDecimalType" arrow::DecimalType"(CFixedSizeBinaryType):
+    cdef cppclass CDecimal128Type" arrow::Decimal128Type"(CFixedSizeBinaryType):
+        CDecimal128Type(int precision, int scale)
         int precision()
         int scale()
-        CDecimalType(int precision, int scale)
 
     cdef cppclass CField" arrow::Field":
         const c_string& name()
diff --git a/python/pyarrow/lib.pxd b/python/pyarrow/lib.pxd
index 6413b83..5abb72b 100644
--- a/python/pyarrow/lib.pxd
+++ b/python/pyarrow/lib.pxd
@@ -81,9 +81,9 @@ cdef class FixedSizeBinaryType(DataType):
         const CFixedSizeBinaryType* fixed_size_binary_type
 
 
-cdef class DecimalType(FixedSizeBinaryType):
+cdef class Decimal128Type(FixedSizeBinaryType):
     cdef:
-        const CDecimalType* decimal_type
+        const CDecimal128Type* decimal128_type
 
 
 cdef class Field:
diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py
index 0aab9a4..a50ef96 100644
--- a/python/pyarrow/pandas_compat.py
+++ b/python/pyarrow/pandas_compat.py
@@ -80,7 +80,7 @@ def get_logical_type(arrow_type):
             return 'list[{}]'.format(get_logical_type(arrow_type.value_type))
         elif isinstance(arrow_type, pa.lib.TimestampType):
             return 'datetimetz' if arrow_type.tz is not None else 'datetime'
-        elif isinstance(arrow_type, pa.lib.DecimalType):
+        elif isinstance(arrow_type, pa.lib.Decimal128Type):
             return 'decimal'
         raise NotImplementedError(str(arrow_type))
 
diff --git a/python/pyarrow/public-api.pxi b/python/pyarrow/public-api.pxi
index 90aff9e..bf670c5 100644
--- a/python/pyarrow/public-api.pxi
+++ b/python/pyarrow/public-api.pxi
@@ -78,7 +78,7 @@ cdef public api object pyarrow_wrap_data_type(
     elif type.get().id() == _Type_FIXED_SIZE_BINARY:
         out = FixedSizeBinaryType()
     elif type.get().id() == _Type_DECIMAL:
-        out = DecimalType()
+        out = Decimal128Type()
     else:
         out = DataType()
 
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index b7b0b18..a4d781a 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -470,7 +470,7 @@ def test_simple_type_construction():
         (pa.binary(length=4), 'bytes'),
         (pa.string(), 'unicode'),
         (pa.list_(pa.list_(pa.int16())), 'list[list[int16]]'),
-        (pa.decimal(18, 3), 'decimal'),
+        (pa.decimal128(18, 3), 'decimal'),
         (pa.timestamp('ms'), 'datetime'),
         (pa.timestamp('us', 'UTC'), 'datetimetz'),
         (pa.time32('s'), 'time'),
diff --git a/python/pyarrow/tests/test_convert_builtin.py b/python/pyarrow/tests/test_convert_builtin.py
index c7a0d49..4c3d9e5 100644
--- a/python/pyarrow/tests/test_convert_builtin.py
+++ b/python/pyarrow/tests/test_convert_builtin.py
@@ -314,7 +314,7 @@ class TestConvertSequence(unittest.TestCase):
 
     def test_decimal(self):
         data = [decimal.Decimal('1234.183'), decimal.Decimal('8094.234')]
-        type = pa.decimal(precision=7, scale=3)
+        type = pa.decimal128(precision=7, scale=3)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
@@ -322,32 +322,32 @@ class TestConvertSequence(unittest.TestCase):
         data = [
             decimal.Decimal('1234234983.183'), decimal.Decimal('80943244.234')
         ]
-        type = pa.decimal(precision=13, scale=3)
+        type = pa.decimal128(precision=13, scale=3)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
     def test_decimal_no_scale(self):
         data = [decimal.Decimal('1234234983'), decimal.Decimal('8094324')]
-        type = pa.decimal(precision=10)
+        type = pa.decimal128(precision=10)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
     def test_decimal_negative(self):
         data = [decimal.Decimal('-1234.234983'), decimal.Decimal('-8.094324')]
-        type = pa.decimal(precision=10, scale=6)
+        type = pa.decimal128(precision=10, scale=6)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
     def test_decimal_no_whole_part(self):
         data = [decimal.Decimal('-.4234983'), decimal.Decimal('.0103943')]
-        type = pa.decimal(precision=7, scale=7)
+        type = pa.decimal128(precision=7, scale=7)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
     def test_decimal_large_integer(self):
         data = [decimal.Decimal('-394029506937548693.42983'),
                 decimal.Decimal('32358695912932.01033')]
-        type = pa.decimal(precision=23, scale=5)
+        type = pa.decimal128(precision=23, scale=5)
         arr = pa.array(data, type=type)
         assert arr.to_pylist() == data
 
diff --git a/python/pyarrow/tests/test_convert_pandas.py b/python/pyarrow/tests/test_convert_pandas.py
index b9c3a12..a2a1d6b 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -828,7 +828,7 @@ class TestPandasConversion(object):
             ]
         })
         converted = pa.Table.from_pandas(expected, preserve_index=False)
-        field = pa.field('decimals', pa.decimal(7, 3))
+        field = pa.field('decimals', pa.decimal128(7, 3))
         schema = pa.schema([field])
         assert converted.schema.equals(schema)
 
@@ -851,7 +851,7 @@ class TestPandasConversion(object):
             ]
         })
         converted = pa.Table.from_pandas(expected, preserve_index=False)
-        field = pa.field('decimals', pa.decimal(12, 6))
+        field = pa.field('decimals', pa.decimal128(12, 6))
         schema = pa.schema([field])
         assert converted.schema.equals(schema)
 
@@ -874,7 +874,7 @@ class TestPandasConversion(object):
             ]
         })
         converted = pa.Table.from_pandas(expected, preserve_index=False)
-        field = pa.field('decimals', pa.decimal(26, 11))
+        field = pa.field('decimals', pa.decimal128(26, 11))
         schema = pa.schema([field])
         assert converted.schema.equals(schema)
 
diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py
index 116f397..dbca139 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -333,7 +333,7 @@ def test_type_schema_pickling():
         pa.date64(),
         pa.timestamp('ms'),
         pa.timestamp('ns'),
-        pa.decimal(12, 2),
+        pa.decimal128(12, 2),
         pa.field('a', 'string', metadata={b'foo': b'bar'})
     ]
 
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index 9eefa33..e352e35 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -56,7 +56,7 @@ def test_is_null():
 
 
 def test_is_decimal():
-    assert types.is_decimal(pa.decimal(19, 4))
+    assert types.is_decimal(pa.decimal128(19, 4))
     assert not types.is_decimal(pa.int32())
 
 
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index abd678b..1563b57 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -290,28 +290,28 @@ cdef class FixedSizeBinaryType(DataType):
             return self.fixed_size_binary_type.byte_width()
 
 
-cdef class DecimalType(FixedSizeBinaryType):
+cdef class Decimal128Type(FixedSizeBinaryType):
 
     cdef void init(self, const shared_ptr[CDataType]& type):
         DataType.init(self, type)
-        self.decimal_type = <const CDecimalType*> type.get()
+        self.decimal128_type = <const CDecimal128Type*> type.get()
 
     def __getstate__(self):
         return (self.precision, self.scale)
 
     def __setstate__(self, state):
-        cdef DataType reconstituted = decimal(*state)
+        cdef DataType reconstituted = decimal128(*state)
         self.init(reconstituted.sp_type)
 
     property precision:
 
         def __get__(self):
-            return self.decimal_type.precision()
+            return self.decimal128_type.precision()
 
     property scale:
 
         def __get__(self):
-            return self.decimal_type.scale()
+            return self.decimal128_type.scale()
 
 
 cdef class Field:
@@ -953,9 +953,9 @@ def float64():
     return primitive_type(_Type_DOUBLE)
 
 
-cpdef DataType decimal(int precision, int scale=0):
+cpdef DataType decimal128(int precision, int scale=0):
     """
-    Create decimal type with precision and scale
+    Create decimal type with precision and scale and 128bit width
 
     Parameters
     ----------
@@ -964,10 +964,10 @@ cpdef DataType decimal(int precision, int scale=0):
 
     Returns
     -------
-    decimal_type : DecimalType
+    decimal_type : Decimal128Type
     """
     cdef shared_ptr[CDataType] decimal_type
-    decimal_type.reset(new CDecimalType(precision, scale))
+    decimal_type.reset(new CDecimal128Type(precision, scale))
     return pyarrow_wrap_data_type(decimal_type)
 
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].