arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [1/2] arrow git commit: ARROW-782: [C++] API cleanup, change public member access in DataType classes to functions, use class instead of struct
Date Mon, 10 Apr 2017 13:25:22 GMT
Repository: arrow
Updated Branches:
  refs/heads/master d1a9aff29 -> 793f4e0c5


http://git-wip-us.apache.org/repos/asf/arrow/blob/793f4e0c/python/pyarrow/array.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/array.pyx b/python/pyarrow/array.pyx
index ee500e6..1c4253e 100644
--- a/python/pyarrow/array.pyx
+++ b/python/pyarrow/array.pyx
@@ -618,7 +618,7 @@ cdef object box_array(const shared_ptr[CArray]& sp_array):
     if data_type == NULL:
         raise ValueError('Array data type was NULL')
 
-    cdef Array arr = _array_classes[data_type.type]()
+    cdef Array arr = _array_classes[data_type.id()]()
     arr.init(sp_array)
     return arr
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/793f4e0c/python/pyarrow/includes/libarrow.pxd
----------------------------------------------------------------------
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index e719e18..71b5c8d 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -61,7 +61,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         TimeUnit_NANO" arrow::TimeUnit::NANO"
 
     cdef cppclass CDataType" arrow::DataType":
-        Type type
+        Type id()
 
         c_bool Equals(const CDataType& other)
 
@@ -72,7 +72,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
 
         int64_t length()
         int64_t null_count()
-        Type type_enum()
+        Type type_id()
 
         c_bool Equals(const CArray& arr)
         c_bool IsNull(int i)
@@ -97,14 +97,14 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         pass
 
     cdef cppclass CTimestampType" arrow::TimestampType"(CFixedWidthType):
-        TimeUnit unit
-        c_string timezone
+        TimeUnit unit()
+        const c_string& timezone()
 
     cdef cppclass CTime32Type" arrow::Time32Type"(CFixedWidthType):
-        TimeUnit unit
+        TimeUnit unit()
 
     cdef cppclass CTime64Type" arrow::Time64Type"(CFixedWidthType):
-        TimeUnit unit
+        TimeUnit unit()
 
     cdef cppclass CDictionaryType" arrow::DictionaryType"(CFixedWidthType):
         CDictionaryType(const shared_ptr[CDataType]& index_type,
@@ -149,15 +149,14 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         int bit_width()
 
     cdef cppclass CDecimalType" arrow::DecimalType"(CFixedSizeBinaryType):
-        int precision
-        int scale
+        int precision()
+        int scale()
         CDecimalType(int precision, int scale)
 
     cdef cppclass CField" arrow::Field":
-        c_string name
-        shared_ptr[CDataType] type
-
-        c_bool nullable
+        const c_string& name()
+        shared_ptr[CDataType] type()
+        c_bool nullable()
 
         CField(const c_string& name, const shared_ptr[CDataType]& type,
                c_bool nullable)
@@ -307,7 +306,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
 
         c_bool is_mutable()
         c_bool is_contiguous()
-        Type type_enum()
+        Type type_id()
         c_bool Equals(const CTensor& other)
 
     CStatus ConcatenateTables(const vector[shared_ptr[CTable]]& tables,

http://git-wip-us.apache.org/repos/asf/arrow/blob/793f4e0c/python/pyarrow/scalar.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/scalar.pyx b/python/pyarrow/scalar.pyx
index 7591ae8..2b6746a 100644
--- a/python/pyarrow/scalar.pyx
+++ b/python/pyarrow/scalar.pyx
@@ -158,26 +158,26 @@ cdef class TimestampValue(ArrayValue):
 
         timezone = None
         tzinfo = None
-        if dtype.timezone.size() > 0:
-            timezone = frombytes(dtype.timezone)
+        if dtype.timezone().size() > 0:
+            timezone = frombytes(dtype.timezone())
             import pytz
             tzinfo = pytz.timezone(timezone)
 
         try:
             pd = _pandas()
-            if dtype.unit == TimeUnit_SECOND:
+            if dtype.unit() == TimeUnit_SECOND:
                 val = val * 1000000000
-            elif dtype.unit == TimeUnit_MILLI:
+            elif dtype.unit() == TimeUnit_MILLI:
                 val = val * 1000000
-            elif dtype.unit == TimeUnit_MICRO:
+            elif dtype.unit() == TimeUnit_MICRO:
                 val = val * 1000
             return pd.Timestamp(val, tz=tzinfo)
         except ImportError:
-            if dtype.unit == TimeUnit_SECOND:
+            if dtype.unit() == TimeUnit_SECOND:
                 result = datetime.datetime.utcfromtimestamp(val)
-            elif dtype.unit == TimeUnit_MILLI:
+            elif dtype.unit() == TimeUnit_MILLI:
                 result = datetime.datetime.utcfromtimestamp(float(val) / 1000)
-            elif dtype.unit == TimeUnit_MICRO:
+            elif dtype.unit() == TimeUnit_MICRO:
                 result = datetime.datetime.utcfromtimestamp(
                     float(val) / 1000000)
             else:
@@ -208,10 +208,6 @@ cdef class DecimalValue(ArrayValue):
     def as_py(self):
         cdef:
             CDecimalArray* ap = <CDecimalArray*> self.sp_array.get()
-            CDecimalType* t = <CDecimalType*> ap.type().get()
-            int bit_width = t.bit_width()
-            int precision = t.precision
-            int scale = t.scale
             c_string s = ap.FormatValue(self.index)
         return decimal.Decimal(s.decode('utf8'))
 
@@ -309,11 +305,11 @@ cdef dict _scalar_classes = {
 cdef object box_scalar(DataType type, const shared_ptr[CArray]& sp_array,
                        int64_t index):
     cdef ArrayValue val
-    if type.type.type == Type_NA:
+    if type.type.id() == Type_NA:
         return NA
     elif sp_array.get().IsNull(index):
         return NA
     else:
-        val = _scalar_classes[type.type.type]()
+        val = _scalar_classes[type.type.id()]()
         val.init(type, sp_array, index)
         return val

http://git-wip-us.apache.org/repos/asf/arrow/blob/793f4e0c/python/pyarrow/schema.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/schema.pyx b/python/pyarrow/schema.pyx
index 4b931bf..4749809 100644
--- a/python/pyarrow/schema.pyx
+++ b/python/pyarrow/schema.pyx
@@ -81,13 +81,13 @@ cdef class TimestampType(DataType):
     property unit:
 
         def __get__(self):
-            return timeunit_to_string(self.ts_type.unit)
+            return timeunit_to_string(self.ts_type.unit())
 
     property tz:
 
         def __get__(self):
-            if self.ts_type.timezone.size() > 0:
-                return frombytes(self.ts_type.timezone)
+            if self.ts_type.timezone().size() > 0:
+                return frombytes(self.ts_type.timezone())
             else:
                 return None
 
@@ -119,7 +119,7 @@ cdef class Field:
     cdef init(self, const shared_ptr[CField]& field):
         self.sp_field = field
         self.field = field.get()
-        self.type = box_data_type(field.get().type)
+        self.type = box_data_type(field.get().type())
 
     @classmethod
     def from_py(cls, object name, DataType type, bint nullable=True):
@@ -137,7 +137,7 @@ cdef class Field:
     property nullable:
 
         def __get__(self):
-            return self.field.nullable
+            return self.field.nullable()
 
     property name:
 
@@ -145,7 +145,7 @@ cdef class Field:
             if box_field(self.sp_field) is None:
                 raise ReferenceError(
                     'Field not initialized (references NULL pointer)')
-            return frombytes(self.field.name)
+            return frombytes(self.field.name())
 
 
 cdef class Schema:
@@ -162,7 +162,7 @@ cdef class Schema:
 
         cdef Field result = Field()
         result.init(self.schema.field(i))
-        result.type = box_data_type(result.field.type)
+        result.type = box_data_type(result.field.type())
 
         return result
 
@@ -442,13 +442,13 @@ cdef DataType box_data_type(const shared_ptr[CDataType]& type):
     if type.get() == NULL:
         return None
 
-    if type.get().type == la.Type_DICTIONARY:
+    if type.get().id() == la.Type_DICTIONARY:
         out = DictionaryType()
-    elif type.get().type == la.Type_TIMESTAMP:
+    elif type.get().id() == la.Type_TIMESTAMP:
         out = TimestampType()
-    elif type.get().type == la.Type_FIXED_SIZE_BINARY:
+    elif type.get().id() == la.Type_FIXED_SIZE_BINARY:
         out = FixedSizeBinaryType()
-    elif type.get().type == la.Type_DECIMAL:
+    elif type.get().id() == la.Type_DECIMAL:
         out = DecimalType()
     else:
         out = DataType()


Mime
View raw message