arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-800: [C++] Boost headers being transitively included in pyarrow
Date Mon, 10 Apr 2017 01:11:42 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 137aade40 -> 72e1e0875


ARROW-800: [C++] Boost headers being transitively included in pyarrow

thanks to @wesm for suggesting the idea of returning `std::string` and doing the dispatching
in c++.

Author: Phillip Cloud <cpcloud@gmail.com>

Closes #518 from cpcloud/ARROW-800 and squashes the following commits:

a983841 [Phillip Cloud] Formatting
ba46502 [Phillip Cloud] decimal namespace and change to FormatValue
f326f3a [Phillip Cloud] Const things
9001432 [Phillip Cloud] Remove ARROW_EXPORT of method inside ARROW_EXPORTed class
0c300ec [Phillip Cloud] ARROW-800: [C++] Boost headers being transitively included in pyarrow


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/72e1e087
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/72e1e087
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/72e1e087

Branch: refs/heads/master
Commit: 72e1e08754003a56b413f49a107d55d61519f7ef
Parents: 137aade
Author: Phillip Cloud <cpcloud@gmail.com>
Authored: Sun Apr 9 21:11:33 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Sun Apr 9 21:11:33 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/array-decimal-test.cc     |  2 ++
 cpp/src/arrow/array.cc                  | 44 +++++++++++++++++-----------
 cpp/src/arrow/array.h                   |  3 +-
 cpp/src/arrow/builder.cc                | 12 ++++----
 cpp/src/arrow/builder.h                 |  6 +++-
 cpp/src/arrow/python/builtin_convert.cc |  2 +-
 cpp/src/arrow/python/helpers.cc         | 12 ++++----
 cpp/src/arrow/python/helpers.h          |  7 ++++-
 cpp/src/arrow/python/pandas_convert.cc  | 10 +++----
 cpp/src/arrow/python/python-test.cc     |  4 +--
 cpp/src/arrow/type_fwd.h                |  2 +-
 cpp/src/arrow/util/CMakeLists.txt       |  1 -
 cpp/src/arrow/util/decimal-test.cc      |  2 ++
 cpp/src/arrow/util/decimal.cc           |  2 ++
 cpp/src/arrow/util/decimal.h            |  2 ++
 python/pyarrow/includes/common.pxd      |  5 ----
 python/pyarrow/includes/libarrow.pxd    |  7 +----
 python/pyarrow/scalar.pyx               |  9 +-----
 18 files changed, 71 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/array-decimal-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array-decimal-test.cc b/cpp/src/arrow/array-decimal-test.cc
index 4c01f92..8353acc 100644
--- a/cpp/src/arrow/array-decimal-test.cc
+++ b/cpp/src/arrow/array-decimal-test.cc
@@ -23,6 +23,7 @@
 #include "arrow/util/decimal.h"
 
 namespace arrow {
+namespace decimal {
 
 TEST(TypesTest, TestDecimal32Type) {
   DecimalType t1(8, 4);
@@ -221,4 +222,5 @@ INSTANTIATE_TEST_CASE_P(Decimal128BuilderTest, Decimal128BuilderTest,
     ::testing::Range(
         DecimalPrecision<int128_t>::minimum, DecimalPrecision<int128_t>::maximum));
 
+}  // namespace decimal
 }  // namespace arrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/array.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.cc b/cpp/src/arrow/array.cc
index 4e73e71..c4a78f3 100644
--- a/cpp/src/arrow/array.cc
+++ b/cpp/src/arrow/array.cc
@@ -310,25 +310,35 @@ bool DecimalArray::IsNegative(int64_t i) const {
   return sign_bitmap_data_ != nullptr ? BitUtil::GetBit(sign_bitmap_data_, i) : false;
 }
 
-template <typename T>
-ARROW_EXPORT Decimal<T> DecimalArray::Value(int64_t i) const {
-  Decimal<T> result;
-  FromBytes(GetValue(i), &result);
-  return result;
-}
-
-template ARROW_EXPORT Decimal32 DecimalArray::Value(int64_t i) const;
-template ARROW_EXPORT Decimal64 DecimalArray::Value(int64_t i) const;
-
-template <>
-ARROW_EXPORT Decimal128 DecimalArray::Value(int64_t i) const {
-  Decimal128 result;
-  FromBytes(GetValue(i), IsNegative(i), &result);
-  return result;
+std::string DecimalArray::FormatValue(int64_t i) const {
+  const auto type_ = std::dynamic_pointer_cast<DecimalType>(type());
+  const int precision = type_->precision;
+  const int scale = type_->scale;
+  const int byte_width = byte_width_;
+  const uint8_t* bytes = GetValue(i);
+  switch (byte_width) {
+    case 4: {
+      decimal::Decimal32 value;
+      decimal::FromBytes(bytes, &value);
+      return decimal::ToString(value, precision, scale);
+    }
+    case 8: {
+      decimal::Decimal64 value;
+      decimal::FromBytes(bytes, &value);
+      return decimal::ToString(value, precision, scale);
+    }
+    case 16: {
+      decimal::Decimal128 value;
+      decimal::FromBytes(bytes, IsNegative(i), &value);
+      return decimal::ToString(value, precision, scale);
+    }
+    default: {
+      DCHECK(false) << "Invalid byte width: " << byte_width;
+      return "";
+    }
+  }
 }
 
-template ARROW_EXPORT Decimal128 DecimalArray::Value(int64_t i) const;
-
 std::shared_ptr<Array> DecimalArray::Slice(int64_t offset, int64_t length) const {
   ConformSliceParams(offset_, length_, &offset, &length);
   return std::make_shared<DecimalArray>(

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/array.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/array.h b/cpp/src/arrow/array.h
index a4117fa..4f8b22e 100644
--- a/cpp/src/arrow/array.h
+++ b/cpp/src/arrow/array.h
@@ -384,8 +384,7 @@ class ARROW_EXPORT DecimalArray : public FixedSizeBinaryArray {
 
   bool IsNegative(int64_t i) const;
 
-  template <typename T>
-  ARROW_EXPORT Decimal<T> Value(int64_t i) const;
+  std::string FormatValue(int64_t i) const;
 
   std::shared_ptr<Array> Slice(int64_t offset, int64_t length) const override;
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/builder.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/builder.cc b/cpp/src/arrow/builder.cc
index a3677ef..4281a61 100644
--- a/cpp/src/arrow/builder.cc
+++ b/cpp/src/arrow/builder.cc
@@ -332,7 +332,7 @@ DecimalBuilder::DecimalBuilder(MemoryPool* pool, const std::shared_ptr<DataType>
       sign_bitmap_data_(nullptr) {}
 
 template <typename T>
-ARROW_EXPORT Status DecimalBuilder::Append(const Decimal<T>& val) {
+ARROW_EXPORT Status DecimalBuilder::Append(const decimal::Decimal<T>& val) {
   DCHECK_EQ(sign_bitmap_, nullptr) << "sign_bitmap_ is not null";
   DCHECK_EQ(sign_bitmap_data_, nullptr) << "sign_bitmap_data_ is not null";
 
@@ -340,11 +340,11 @@ ARROW_EXPORT Status DecimalBuilder::Append(const Decimal<T>&
val) {
   return FixedSizeBinaryBuilder::Append(reinterpret_cast<const uint8_t*>(&val.value));
 }
 
-template ARROW_EXPORT Status DecimalBuilder::Append(const Decimal32& val);
-template ARROW_EXPORT Status DecimalBuilder::Append(const Decimal64& val);
+template ARROW_EXPORT Status DecimalBuilder::Append(const decimal::Decimal32& val);
+template ARROW_EXPORT Status DecimalBuilder::Append(const decimal::Decimal64& val);
 
 template <>
-ARROW_EXPORT Status DecimalBuilder::Append(const Decimal128& value) {
+ARROW_EXPORT Status DecimalBuilder::Append(const decimal::Decimal128& value) {
   DCHECK_NE(sign_bitmap_, nullptr) << "sign_bitmap_ is null";
   DCHECK_NE(sign_bitmap_data_, nullptr) << "sign_bitmap_data_ is null";
 
@@ -352,7 +352,7 @@ ARROW_EXPORT Status DecimalBuilder::Append(const Decimal128& value)
{
   uint8_t stack_bytes[16] = {0};
   uint8_t* bytes = stack_bytes;
   bool is_negative;
-  ToBytes(value, &bytes, &is_negative);
+  decimal::ToBytes(value, &bytes, &is_negative);
   RETURN_NOT_OK(FixedSizeBinaryBuilder::Append(bytes));
 
   // TODO(phillipc): calculate the proper storage size here (do we have a function to do
@@ -363,7 +363,7 @@ ARROW_EXPORT Status DecimalBuilder::Append(const Decimal128& value)
{
   return Status::OK();
 }
 
-template ARROW_EXPORT Status DecimalBuilder::Append(const Decimal128& val);
+template ARROW_EXPORT Status DecimalBuilder::Append(const decimal::Decimal128& val);
 
 Status DecimalBuilder::Init(int64_t capacity) {
   RETURN_NOT_OK(FixedSizeBinaryBuilder::Init(capacity));

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/builder.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/builder.h b/cpp/src/arrow/builder.h
index d42ab5b..6876916 100644
--- a/cpp/src/arrow/builder.h
+++ b/cpp/src/arrow/builder.h
@@ -37,9 +37,13 @@ namespace arrow {
 
 class Array;
 
+namespace decimal {
+
 template <typename T>
 struct Decimal;
 
+}  // namespace decimal
+
 static constexpr int64_t kMinBuilderCapacity = 1 << 5;
 
 /// Base class for all data array builders.
@@ -421,7 +425,7 @@ class ARROW_EXPORT DecimalBuilder : public FixedSizeBinaryBuilder {
   explicit DecimalBuilder(MemoryPool* pool, const std::shared_ptr<DataType>& type);
 
   template <typename T>
-  ARROW_EXPORT Status Append(const Decimal<T>& val);
+  ARROW_EXPORT Status Append(const decimal::Decimal<T>& val);
 
   Status Init(int64_t capacity) override;
   Status Resize(int64_t capacity) override;

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/python/builtin_convert.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/builtin_convert.cc b/cpp/src/arrow/python/builtin_convert.cc
index a064a3d..1ae13f3 100644
--- a/cpp/src/arrow/python/builtin_convert.cc
+++ b/cpp/src/arrow/python/builtin_convert.cc
@@ -523,7 +523,7 @@ class ListConverter : public TypedConverter<ListBuilder> {
 
 #define DECIMAL_CONVERT_CASE(bit_width, item, builder)        \
   case bit_width: {                                           \
-    arrow::Decimal##bit_width out;                            \
+    arrow::decimal::Decimal##bit_width out;                   \
     RETURN_NOT_OK(PythonDecimalToArrowDecimal((item), &out)); \
     RETURN_NOT_OK((builder)->Append(out));                    \
     break;                                                    \

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/python/helpers.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/helpers.cc b/cpp/src/arrow/python/helpers.cc
index ffba7bb..3d3d07a 100644
--- a/cpp/src/arrow/python/helpers.cc
+++ b/cpp/src/arrow/python/helpers.cc
@@ -74,7 +74,8 @@ Status ImportFromModule(const OwnedRef& module, const std::string&
name, OwnedRe
 }
 
 template <typename T>
-Status PythonDecimalToArrowDecimal(PyObject* python_decimal, Decimal<T>* arrow_decimal)
{
+Status PythonDecimalToArrowDecimal(
+    PyObject* python_decimal, decimal::Decimal<T>* arrow_decimal) {
   // Call Python's str(decimal_object)
   OwnedRef str_obj(PyObject_Str(python_decimal));
   RETURN_IF_PYERROR();
@@ -92,11 +93,11 @@ Status PythonDecimalToArrowDecimal(PyObject* python_decimal, Decimal<T>*
arrow_d
 }
 
 template Status PythonDecimalToArrowDecimal(
-    PyObject* python_decimal, Decimal32* arrow_decimal);
+    PyObject* python_decimal, decimal::Decimal32* arrow_decimal);
 template Status PythonDecimalToArrowDecimal(
-    PyObject* python_decimal, Decimal64* arrow_decimal);
+    PyObject* python_decimal, decimal::Decimal64* arrow_decimal);
 template Status PythonDecimalToArrowDecimal(
-    PyObject* python_decimal, Decimal128* arrow_decimal);
+    PyObject* python_decimal, decimal::Decimal128* arrow_decimal);
 
 Status InferDecimalPrecisionAndScale(
     PyObject* python_decimal, int* precision, int* scale) {
@@ -111,7 +112,8 @@ Status InferDecimalPrecisionAndScale(
   auto size = str.size;
 
   std::string c_string(bytes, size);
-  return FromString(c_string, static_cast<Decimal32*>(nullptr), precision, scale);
+  return FromString(
+      c_string, static_cast<decimal::Decimal32*>(nullptr), precision, scale);
 }
 
 Status DecimalFromString(

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/python/helpers.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/helpers.h b/cpp/src/arrow/python/helpers.h
index a19b25f..77fde26 100644
--- a/cpp/src/arrow/python/helpers.h
+++ b/cpp/src/arrow/python/helpers.h
@@ -29,9 +29,13 @@
 
 namespace arrow {
 
+namespace decimal {
+
 template <typename T>
 struct Decimal;
 
+}  // namespace decimal
+
 namespace py {
 
 class OwnedRef;
@@ -43,7 +47,8 @@ Status ImportFromModule(
     const OwnedRef& module, const std::string& module_name, OwnedRef* ref);
 
 template <typename T>
-Status PythonDecimalToArrowDecimal(PyObject* python_decimal, Decimal<T>* arrow_decimal);
+Status PythonDecimalToArrowDecimal(
+    PyObject* python_decimal, decimal::Decimal<T>* arrow_decimal);
 
 Status InferDecimalPrecisionAndScale(
     PyObject* python_decimal, int* precision = nullptr, int* scale = nullptr);

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/python/pandas_convert.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/pandas_convert.cc b/cpp/src/arrow/python/pandas_convert.cc
index 5bb8e45..1a250e8 100644
--- a/cpp/src/arrow/python/pandas_convert.cc
+++ b/cpp/src/arrow/python/pandas_convert.cc
@@ -530,7 +530,7 @@ Status PandasConverter::ConvertDates() {
 
 #define CONVERT_DECIMAL_CASE(bit_width, builder, object)      \
   case bit_width: {                                           \
-    Decimal##bit_width d;                                     \
+    decimal::Decimal##bit_width d;                            \
     RETURN_NOT_OK(PythonDecimalToArrowDecimal((object), &d)); \
     RETURN_NOT_OK((builder).Append(d));                       \
     break;                                                    \
@@ -620,7 +620,7 @@ Status PandasConverter::ConvertObjectFixedWidthBytes(
 
 template <typename T>
 Status validate_precision(int precision) {
-  constexpr static const int maximum_precision = DecimalPrecision<T>::maximum;
+  constexpr static const int maximum_precision = decimal::DecimalPrecision<T>::maximum;
   if (!(precision > 0 && precision <= maximum_precision)) {
     std::stringstream ss;
     ss << "Invalid precision: " << precision << ". Minimum is 1, maximum
is "
@@ -636,7 +636,7 @@ Status RawDecimalToString(
   DCHECK_NE(bytes, nullptr);
   DCHECK_NE(result, nullptr);
   RETURN_NOT_OK(validate_precision<T>(precision));
-  Decimal<T> decimal;
+  decimal::Decimal<T> decimal;
   FromBytes(bytes, &decimal);
   *result = ToString(decimal, precision, scale);
   return Status::OK();
@@ -651,8 +651,8 @@ Status RawDecimalToString(const uint8_t* bytes, int precision, int scale,
     bool is_negative, std::string* result) {
   DCHECK_NE(bytes, nullptr);
   DCHECK_NE(result, nullptr);
-  RETURN_NOT_OK(validate_precision<int128_t>(precision));
-  Decimal128 decimal;
+  RETURN_NOT_OK(validate_precision<boost::multiprecision::int128_t>(precision));
+  decimal::Decimal128 decimal;
   FromBytes(bytes, is_negative, &decimal);
   *result = ToString(decimal, precision, scale);
   return Status::OK();

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/python/python-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/python-test.cc b/cpp/src/arrow/python/python-test.cc
index b63d2ff..a4a11c0 100644
--- a/cpp/src/arrow/python/python-test.cc
+++ b/cpp/src/arrow/python/python-test.cc
@@ -63,8 +63,8 @@ TEST(DecimalTest, TestPythonDecimalToArrowDecimal128) {
   ASSERT_NE(pydecimal.obj(), nullptr);
   ASSERT_EQ(PyErr_Occurred(), nullptr);
 
-  Decimal128 arrow_decimal;
-  int128_t boost_decimal(decimal_string);
+  decimal::Decimal128 arrow_decimal;
+  boost::multiprecision::int128_t boost_decimal(decimal_string);
   PyObject* obj = pydecimal.obj();
   ASSERT_OK(PythonDecimalToArrowDecimal(obj, &arrow_decimal));
   ASSERT_EQ(boost_decimal, arrow_decimal.value);

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/type_fwd.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type_fwd.h b/cpp/src/arrow/type_fwd.h
index acf12c3..2bb05f8 100644
--- a/cpp/src/arrow/type_fwd.h
+++ b/cpp/src/arrow/type_fwd.h
@@ -147,7 +147,7 @@ std::shared_ptr<DataType> ARROW_EXPORT binary();
 
 std::shared_ptr<DataType> ARROW_EXPORT date32();
 std::shared_ptr<DataType> ARROW_EXPORT date64();
-std::shared_ptr<DataType> ARROW_EXPORT decimal(int precision, int scale);
+std::shared_ptr<DataType> ARROW_EXPORT decimal_type(int precision, int scale);
 
 }  // namespace arrow
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/CMakeLists.txt b/cpp/src/arrow/util/CMakeLists.txt
index 054f110..9aa8bae 100644
--- a/cpp/src/arrow/util/CMakeLists.txt
+++ b/cpp/src/arrow/util/CMakeLists.txt
@@ -22,7 +22,6 @@
 # Headers: top level
 install(FILES
   bit-util.h
-  decimal.h
   logging.h
   macros.h
   random.h

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/util/decimal-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/decimal-test.cc b/cpp/src/arrow/util/decimal-test.cc
index 1e22643..dcaa9af 100644
--- a/cpp/src/arrow/util/decimal-test.cc
+++ b/cpp/src/arrow/util/decimal-test.cc
@@ -23,6 +23,7 @@
 #include "arrow/test-util.h"
 
 namespace arrow {
+namespace decimal {
 
 template <typename T>
 class DecimalTest : public ::testing::Test {
@@ -158,4 +159,5 @@ TEST(DecimalTest, TestDecimal128StringAndBytesRoundTrip) {
 
   ASSERT_EQ(expected.value, result.value);
 }
+}  // namespace decimal
 }  // namespace arrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/util/decimal.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc
index 1ac3471..3b8a3ff 100644
--- a/cpp/src/arrow/util/decimal.cc
+++ b/cpp/src/arrow/util/decimal.cc
@@ -20,6 +20,7 @@
 #include <boost/regex.hpp>
 
 namespace arrow {
+namespace decimal {
 
 static const boost::regex DECIMAL_PATTERN("(\\+?|-?)((0*)(\\d*))(\\.(\\d+))?");
 
@@ -138,4 +139,5 @@ void ToBytes(const Decimal128& decimal, uint8_t** bytes, bool* is_negative)
{
   *is_negative = backend.isneg();
 }
 
+}  // namespace decimal
 }  // namespace arrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/cpp/src/arrow/util/decimal.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/decimal.h b/cpp/src/arrow/util/decimal.h
index 46883e3..c73bae1 100644
--- a/cpp/src/arrow/util/decimal.h
+++ b/cpp/src/arrow/util/decimal.h
@@ -31,6 +31,7 @@
 #include <boost/multiprecision/cpp_int.hpp>
 
 namespace arrow {
+namespace decimal {
 
 using boost::multiprecision::int128_t;
 
@@ -140,5 +141,6 @@ ARROW_EXPORT void ToBytes(const Decimal32& value, uint8_t** bytes);
 ARROW_EXPORT void ToBytes(const Decimal64& value, uint8_t** bytes);
 ARROW_EXPORT void ToBytes(const Decimal128& decimal, uint8_t** bytes, bool* is_negative);
 
+}  // namespace decimal
 }  // namespace arrow
 #endif  // ARROW_DECIMAL_H

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/python/pyarrow/includes/common.pxd
----------------------------------------------------------------------
diff --git a/python/pyarrow/includes/common.pxd b/python/pyarrow/includes/common.pxd
index 4860334..ab38ff3 100644
--- a/python/pyarrow/includes/common.pxd
+++ b/python/pyarrow/includes/common.pxd
@@ -51,11 +51,6 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         c_bool IsTypeError()
 
 
-cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil:
-    cdef cppclass int128_t:
-        pass
-
-
 cdef inline object PyObject_to_object(PyObject* o):
     # Cast to "object" increments reference count
     cdef object result = <object> o

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/python/pyarrow/includes/libarrow.pxd
----------------------------------------------------------------------
diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd
index 73d96b2..e719e18 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -60,11 +60,6 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         TimeUnit_MICRO" arrow::TimeUnit::MICRO"
         TimeUnit_NANO" arrow::TimeUnit::NANO"
 
-    cdef cppclass Decimal[T]:
-        Decimal(const T&)
-
-    cdef c_string ToString[T](const Decimal[T]&, int, int)
-
     cdef cppclass CDataType" arrow::DataType":
         Type type
 
@@ -226,7 +221,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
         const uint8_t* GetValue(int i)
 
     cdef cppclass CDecimalArray" arrow::DecimalArray"(CFixedSizeBinaryArray):
-        Decimal[T] Value[T](int i)
+        c_string FormatValue(int i)
 
     cdef cppclass CListArray" arrow::ListArray"(CArray):
         const int32_t* raw_value_offsets()

http://git-wip-us.apache.org/repos/asf/arrow/blob/72e1e087/python/pyarrow/scalar.pyx
----------------------------------------------------------------------
diff --git a/python/pyarrow/scalar.pyx b/python/pyarrow/scalar.pyx
index 196deed..7591ae8 100644
--- a/python/pyarrow/scalar.pyx
+++ b/python/pyarrow/scalar.pyx
@@ -17,7 +17,6 @@
 
 from pyarrow.schema cimport DataType, box_data_type
 
-from pyarrow.includes.common cimport int128_t
 from pyarrow.compat import frombytes
 import pyarrow.schema as schema
 import decimal
@@ -213,13 +212,7 @@ cdef class DecimalValue(ArrayValue):
             int bit_width = t.bit_width()
             int precision = t.precision
             int scale = t.scale
-            c_string s
-        if bit_width == 32:
-            s = ToString[int32_t](ap.Value[int32_t](self.index), precision, scale)
-        elif bit_width == 64:
-            s = ToString[int64_t](ap.Value[int64_t](self.index), precision, scale)
-        elif bit_width == 128:
-            s = ToString[int128_t](ap.Value[int128_t](self.index), precision, scale)
+            c_string s = ap.FormatValue(self.index)
         return decimal.Decimal(s.decode('utf8'))
 
 


Mime
View raw message