[Python-modules-commits] [python-feather-format] 01/03: Import python-feather-format_0.1.2.orig.tar.gz

ChangZhuo Chen czchen at moszumanska.debian.org
Mon Apr 11 15:17:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

czchen pushed a commit to branch master
in repository python-feather-format.

commit a14984bf3465d6ca9724e3433de9ec72383efbb4
Author: ChangZhuo Chen (陳昌倬) <czchen at debian.org>
Date:   Mon Apr 11 23:03:01 2016 +0800

    Import python-feather-format_0.1.2.orig.tar.gz
---
 PKG-INFO                            |   2 +-
 feather/ext.cpp                     |   6 +-
 feather/ext.pyx                     |   2 +-
 feather/interop.h                   |  25 +++--
 feather/libfeather.pxd              |   2 +-
 feather/tests/test_reader.py        |  16 ++-
 feather/version.py                  |   2 +-
 feather_format.egg-info/PKG-INFO    |   2 +-
 feather_format.egg-info/SOURCES.txt |   3 +
 setup.py                            |   2 +-
 src/feather/CMakeLists.txt          |   3 +
 src/feather/feather-c.cc            | 216 ++++++++++++++++++++++++++++++++++++
 src/feather/feather-c.h             | 199 +++++++++++++++++++++++++++++++++
 src/feather/metadata.cc             |   2 +
 src/feather/reader.cc               |  26 +++--
 src/feather/reader.h                |  27 +++--
 src/feather/status.h                |   1 +
 src/feather/tests/c-api-test.cc     | 194 ++++++++++++++++++++++++++++++++
 src/feather/tests/writer-test.cc    |  12 +-
 19 files changed, 694 insertions(+), 48 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 2c5d6f3..84bee28 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: feather-format
-Version: 0.1.1
+Version: 0.1.2
 Summary: Python interface to the Apache Arrow-based Feather File Format
 Home-page: http://github.com/wesm/feather
 Author: Wes McKinney
diff --git a/feather/ext.cpp b/feather/ext.cpp
index 58e70a5..5176331 100644
--- a/feather/ext.cpp
+++ b/feather/ext.cpp
@@ -3175,7 +3175,7 @@ static PyObject *__pyx_pf_7feather_3ext_13FeatherReader_11num_columns___get__(st
  * 
  *     def read_array(self, int i):             # <<<<<<<<<<<<<<
  *         cdef:
- *             shared_ptr[Column] col
+ *             unique_ptr[Column] col
  */
 
 /* Python wrapper */
@@ -3206,7 +3206,7 @@ static PyObject *__pyx_pw_7feather_3ext_13FeatherReader_3read_array(PyObject *__
 }
 
 static PyObject *__pyx_pf_7feather_3ext_13FeatherReader_2read_array(struct __pyx_obj_7feather_3ext_FeatherReader *__pyx_v_self, int __pyx_v_i) {
-  std::shared_ptr<feather::Column>  __pyx_v_col;
+  std::unique_ptr<feather::Column>  __pyx_v_col;
   feather::Column *__pyx_v_cp;
   PyObject *__pyx_v_values = NULL;
   PyObject *__pyx_r = NULL;
@@ -3474,7 +3474,7 @@ static PyObject *__pyx_pf_7feather_3ext_13FeatherReader_2read_array(struct __pyx
  * 
  *     def read_array(self, int i):             # <<<<<<<<<<<<<<
  *         cdef:
- *             shared_ptr[Column] col
+ *             unique_ptr[Column] col
  */
 
   /* function exit code */
diff --git a/feather/ext.pyx b/feather/ext.pyx
index d7952ff..4b507ee 100644
--- a/feather/ext.pyx
+++ b/feather/ext.pyx
@@ -168,7 +168,7 @@ cdef class FeatherReader:
 
     def read_array(self, int i):
         cdef:
-            shared_ptr[Column] col
+            unique_ptr[Column] col
             Column* cp
 
         if i < 0 or i >= self.num_columns:
diff --git a/feather/interop.h b/feather/interop.h
index 74f0ab2..4c94efb 100644
--- a/feather/interop.h
+++ b/feather/interop.h
@@ -47,25 +47,28 @@ struct npy_traits<NPY_BOOL> {
   }
 };
 
-#define NPY_INT_DECL(TYPE, T)                                           \
+#define NPY_INT_DECL(TYPE, FTYPE, T)                                    \
   template <>                                                           \
   struct npy_traits<NPY_##TYPE> {                                       \
     typedef T value_type;                                               \
-    static constexpr PrimitiveType::type feather_type = PrimitiveType::TYPE; \
+    static constexpr PrimitiveType::type feather_type = PrimitiveType::FTYPE; \
     static constexpr bool supports_nulls = false;                       \
     static inline bool isnull(T v) {                                    \
       return false;                                                     \
     }                                                                   \
   };
 
-NPY_INT_DECL(INT8, int8_t);
-NPY_INT_DECL(INT16, int16_t);
-NPY_INT_DECL(INT32, int32_t);
-NPY_INT_DECL(INT64, int64_t);
-NPY_INT_DECL(UINT8, uint8_t);
-NPY_INT_DECL(UINT16, uint16_t);
-NPY_INT_DECL(UINT32, uint32_t);
-NPY_INT_DECL(UINT64, uint64_t);
+NPY_INT_DECL(INT8, INT8, int8_t);
+NPY_INT_DECL(INT16, INT16, int16_t);
+NPY_INT_DECL(INT32, INT32, int32_t);
+NPY_INT_DECL(INT64, INT64, int64_t);
+NPY_INT_DECL(LONGLONG, INT64, int64_t);
+
+NPY_INT_DECL(UINT8, UINT8, uint8_t);
+NPY_INT_DECL(UINT16, UINT16, uint16_t);
+NPY_INT_DECL(UINT32, UINT32, uint32_t);
+NPY_INT_DECL(UINT64, UINT64, uint64_t);
+NPY_INT_DECL(ULONGLONG, UINT64, uint64_t);
 
 template <>
 struct npy_traits<NPY_FLOAT32> {
@@ -414,10 +417,12 @@ Status pandas_masked_to_primitive(PyObject* ao, PyObject* mo,
     TO_FEATHER_CASE(INT16);
     TO_FEATHER_CASE(INT32);
     TO_FEATHER_CASE(INT64);
+    TO_FEATHER_CASE(LONGLONG);
     TO_FEATHER_CASE(UINT8);
     TO_FEATHER_CASE(UINT16);
     TO_FEATHER_CASE(UINT32);
     TO_FEATHER_CASE(UINT64);
+    TO_FEATHER_CASE(ULONGLONG);
     TO_FEATHER_CASE(FLOAT32);
     TO_FEATHER_CASE(FLOAT64);
     TO_FEATHER_CASE(OBJECT);
diff --git a/feather/libfeather.pxd b/feather/libfeather.pxd
index d22ac61..c50d577 100644
--- a/feather/libfeather.pxd
+++ b/feather/libfeather.pxd
@@ -197,4 +197,4 @@ cdef extern from "feather/api.h" namespace "feather" nogil:
         int64_t num_rows()
         int64_t num_columns()
 
-        Status GetColumn(int i, shared_ptr[Column]* out)
+        Status GetColumn(int i, unique_ptr[Column]* out)
diff --git a/feather/tests/test_reader.py b/feather/tests/test_reader.py
index 7ec585d..e180193 100644
--- a/feather/tests/test_reader.py
+++ b/feather/tests/test_reader.py
@@ -116,7 +116,8 @@ class TestFeatherReader(unittest.TestCase):
     def test_integer_no_nulls(self):
         data = {}
 
-        numpy_dtypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8']
+        numpy_dtypes = ['i1', 'i2', 'i4', 'i8',
+                        'u1', 'u2', 'u4', 'u8']
         num_values = 100
 
         for dtype in numpy_dtypes:
@@ -129,6 +130,19 @@ class TestFeatherReader(unittest.TestCase):
         df = pd.DataFrame(data)
         self._check_pandas_roundtrip(df)
 
+    def test_platform_numpy_integers(self):
+        data = {}
+
+        numpy_dtypes = ['longlong']
+        num_values = 100
+
+        for dtype in numpy_dtypes:
+            values = np.random.randint(0, 100, size=num_values)
+            data[dtype] = values.astype(dtype)
+
+        df = pd.DataFrame(data)
+        self._check_pandas_roundtrip(df)
+
     def test_integer_with_nulls(self):
         # pandas requires upcast to float dtype
         path = random_path()
diff --git a/feather/version.py b/feather/version.py
index 5e2655d..7c21425 100644
--- a/feather/version.py
+++ b/feather/version.py
@@ -1,4 +1,4 @@
 
 # THIS FILE IS GENERATED FROM SETUP.PY
-version = '0.1.1'
+version = '0.1.2'
 isrelease = 'True'
\ No newline at end of file
diff --git a/feather_format.egg-info/PKG-INFO b/feather_format.egg-info/PKG-INFO
index 2c5d6f3..84bee28 100644
--- a/feather_format.egg-info/PKG-INFO
+++ b/feather_format.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: feather-format
-Version: 0.1.1
+Version: 0.1.2
 Summary: Python interface to the Apache Arrow-based Feather File Format
 Home-page: http://github.com/wesm/feather
 Author: Wes McKinney
diff --git a/feather_format.egg-info/SOURCES.txt b/feather_format.egg-info/SOURCES.txt
index 249f79e..ff30b83 100644
--- a/feather_format.egg-info/SOURCES.txt
+++ b/feather_format.egg-info/SOURCES.txt
@@ -22,6 +22,8 @@ src/feather/api.h
 src/feather/buffer.cc
 src/feather/buffer.h
 src/feather/common.h
+src/feather/feather-c.cc
+src/feather/feather-c.h
 src/feather/io.cc
 src/feather/io.h
 src/feather/metadata.cc
@@ -37,6 +39,7 @@ src/feather/types.cc
 src/feather/types.h
 src/feather/writer.cc
 src/feather/writer.h
+src/feather/tests/c-api-test.cc
 src/feather/tests/io-test.cc
 src/feather/tests/metadata-test.cc
 src/feather/tests/test-common.h
diff --git a/setup.py b/setup.py
index 099bf9b..c42b7ed 100644
--- a/setup.py
+++ b/setup.py
@@ -34,7 +34,7 @@ if Cython.__version__ < '0.19.1':
 
 MAJOR = 0
 MINOR = 1
-MICRO = 1
+MICRO = 2
 VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
 ISRELEASED = True
 
diff --git a/src/feather/CMakeLists.txt b/src/feather/CMakeLists.txt
index 42dc584..1ef3c4c 100644
--- a/src/feather/CMakeLists.txt
+++ b/src/feather/CMakeLists.txt
@@ -14,6 +14,7 @@
 
 set(LIBFEATHER_SRCS
   buffer.cc
+  feather-c.cc
   io.cc
   metadata.cc
   reader.cc
@@ -59,6 +60,7 @@ else()
   )
 endif()
 
+ADD_FEATHER_TEST(tests/c-api-test)
 ADD_FEATHER_TEST(tests/io-test)
 ADD_FEATHER_TEST(tests/metadata-test)
 ADD_FEATHER_TEST(tests/writer-test)
@@ -88,6 +90,7 @@ install(FILES
   api.h
   buffer.h
   common.h
+  feather-c.h
   io.h
   metadata.h
   reader.h
diff --git a/src/feather/feather-c.cc b/src/feather/feather-c.cc
new file mode 100644
index 0000000..db14e30
--- /dev/null
+++ b/src/feather/feather-c.cc
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2016 Feather Developers
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdlib>
+#include <cstdint>
+#include <string>
+
+#include "feather/reader.h"
+#include "feather/types.h"
+#include "feather/writer.h"
+#include "feather/feather-c.h"
+
+using feather::Column;
+using feather::ColumnType;
+using feather::PrimitiveArray;
+using feather::PrimitiveType;
+using feather::Status;
+using feather::TableReader;
+using feather::TableWriter;
+
+static PrimitiveType::type FromCFeatherType(feather_type ctype) {
+  return static_cast<PrimitiveType::type>(static_cast<int>(ctype));
+}
+
+static feather_type ToCFeatherType(PrimitiveType::type type) {
+  return static_cast<feather_type>(static_cast<int>(type));
+}
+
+static feather_column_type ToCFeatherColumnType(ColumnType::type type) {
+  return static_cast<feather_column_type>(static_cast<int>(type));
+}
+
+static Status ToCFeatherArray(const PrimitiveArray& values, feather_array_t* out) {
+  out->type = ToCFeatherType(values.type);
+  out->length = values.length;
+  out->null_count = values.null_count;
+
+  out->nulls = values.nulls;
+  out->values = values.values;
+  out->offsets = values.offsets;
+
+  return Status::OK();
+}
+
+static Status FromCFeatherArray(feather_array_t* carr, PrimitiveArray* out) {
+  out->type = FromCFeatherType(carr->type);
+  out->length = carr->length;
+  out->null_count = carr->null_count;
+
+  out->nulls = carr->nulls;
+  out->values = carr->values;
+  out->offsets = carr->offsets;
+
+  return Status::OK();
+}
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* confuse emacs indentation */
+}
+#endif
+#endif
+
+static feather_status get_feather_status(const Status& s) {
+  if (s.ok()) {
+    return FEATHER_OK;
+  } else if (s.IsOutOfMemory()) {
+    return FEATHER_OOM;
+  } else if (s.IsKeyError()) {
+    return FEATHER_KEY_ERROR;
+  } else if (s.IsInvalid()) {
+    return FEATHER_INVALID;
+  } else if (s.IsIOError()) {
+    return FEATHER_IO_ERROR;
+  } else if (s.IsNotImplemented()) {
+    return FEATHER_NOT_IMPLEMENTED;
+  } else {
+    return FEATHER_UNKNOWN;
+  }
+}
+
+#define FEATHER_CHECK_STATUS(s) do {                \
+    Status _s = (s);                                \
+    if (!_s.ok()) return get_feather_status(_s);    \
+  } while (0);
+
+#define FEATHER_CHECK_MALLOC(ptr) do {          \
+    if ((ptr) == nullptr) {                     \
+      return FEATHER_OOM;                       \
+    }                                           \
+  } while (0);
+
+/* Writer C API */
+
+feather_status
+feather_writer_open_file(const char* path, feather_writer_t** out) {
+  std::unique_ptr<TableWriter> writer;
+  try {
+    std::string str_path(path);
+    FEATHER_CHECK_STATUS(TableWriter::OpenFile(str_path, &writer));
+  } catch (const std::exception& e) {
+    return FEATHER_OOM;
+  }
+  *out = reinterpret_cast<feather_writer_t*>(writer.release());
+  return FEATHER_OK;
+}
+
+void feather_writer_set_num_rows(feather_writer_t* self, int64_t num_rows) {
+  reinterpret_cast<TableWriter*>(self)->SetNumRows(num_rows);
+}
+
+feather_status
+feather_writer_append_plain(feather_writer_t* self, const char* name,
+    feather_array_t* values) {
+  TableWriter* writer = reinterpret_cast<TableWriter*>(self);
+  PrimitiveArray cpp_values;
+
+  FEATHER_CHECK_STATUS(FromCFeatherArray(values, &cpp_values));
+
+  try {
+    std::string cpp_name(name);
+    return get_feather_status(writer->AppendPlain(cpp_name, cpp_values));
+  } catch (const std::exception& e) {
+    return FEATHER_OOM;
+  }
+}
+
+feather_status
+feather_writer_close(feather_writer_t* self) {
+  return get_feather_status(
+      reinterpret_cast<TableWriter*>(self)->Finalize());
+}
+
+feather_status
+feather_writer_free(feather_writer_t* self) {
+  delete reinterpret_cast<TableWriter*>(self);
+  return FEATHER_OK;
+}
+
+/* Reader C API */
+
+feather_status
+feather_column_free(feather_column_t* self) {
+  delete reinterpret_cast<Column*>(self->data);
+  return FEATHER_OK;
+}
+
+feather_status
+feather_reader_open_file(const char* path, feather_reader_t** out) {
+  std::unique_ptr<TableReader> reader;
+  try {
+    std::string str_path(path);
+    FEATHER_CHECK_STATUS(TableReader::OpenFile(str_path, &reader));
+  } catch (const std::exception& e) {
+    return FEATHER_OOM;
+  }
+  *out = reinterpret_cast<feather_reader_t*>(reader.release());
+  return FEATHER_OK;
+}
+
+int64_t
+feather_reader_num_rows(feather_reader_t* self) {
+  return reinterpret_cast<TableReader*>(self)->num_rows();
+}
+
+int64_t
+feather_reader_num_columns(feather_reader_t* self) {
+  return reinterpret_cast<TableReader*>(self)->num_columns();
+}
+
+feather_status
+feather_reader_get_column(feather_reader_t* self, int i, feather_column_t* out) {
+  TableReader* reader = reinterpret_cast<TableReader*>(self);
+  std::unique_ptr<Column> col;
+  FEATHER_CHECK_STATUS(reader->GetColumn(i, &col));
+
+  out->type = ToCFeatherColumnType(col->type());
+  out->name = col->name().c_str();
+
+  FEATHER_CHECK_STATUS(ToCFeatherArray(col->values(), &out->values));
+
+  out->data = reinterpret_cast<void*>(col.release());
+
+  return FEATHER_OK;
+}
+
+feather_status
+feather_reader_close(feather_reader_t* self) {
+  return FEATHER_OK;
+}
+
+feather_status
+feather_reader_free(feather_reader_t* self) {
+  delete reinterpret_cast<TableReader*>(self);
+  return FEATHER_OK;
+}
+
+#ifdef __cplusplus
+#if 0 /* confuse emacs indentation */
+{
+#endif
+}
+#endif
diff --git a/src/feather/feather-c.h b/src/feather/feather-c.h
new file mode 100644
index 0000000..3355b76
--- /dev/null
+++ b/src/feather/feather-c.h
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2016 Feather Developers
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FEATHER_FEATHER_C_H
+#define FEATHER_FEATHER_C_H
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* confuse emacs indentation */
+}
+#endif
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef enum {
+  FEATHER_OK = 0,
+  FEATHER_OOM = 1,
+  FEATHER_KEY_ERROR = 2,
+  FEATHER_INVALID = 3,
+  FEATHER_IO_ERROR = 4,
+  FEATHER_NOT_IMPLEMENTED = 10,
+  FEATHER_UNKNOWN = 50
+} feather_status;
+
+typedef enum {
+  FEATHER_BOOL = 0,
+  FEATHER_INT8 = 1,
+  FEATHER_INT16 = 2,
+  FEATHER_INT32 = 3,
+  FEATHER_INT64 = 4,
+  FEATHER_UINT8 = 5,
+  FEATHER_UINT16 = 6,
+  FEATHER_UINT32 = 7,
+  FEATHER_UINT64 = 8,
+  FEATHER_FLOAT = 9,
+  FEATHER_DOUBLE = 10,
+  FEATHER_UTF8 = 11,
+  FEATHER_BINARY = 12
+} feather_type;
+
+/*
+  Column C API
+ */
+
+typedef enum {
+  FEATHER_COLUMN_PRIMITIVE = 0,
+  FEATHER_COLUMN_CATEGORY = 1,
+  FEATHER_COLUMN_TIMESTAMP = 2,
+  FEATHER_COLUMN_DATE = 3,
+  FEATHER_COLUMN_TIME = 4,
+} feather_column_type;
+
+typedef enum {
+  FEATHER_UNIT_SECOND = 0,
+  FEATHER_UNIT_MILLISECOND = 1,
+  FEATHER_UNIT_MICROSECOND = 2,
+  FEATHER_UNIT_NANOSECOND = 3
+} feather_time_unit;
+
+typedef struct {
+  feather_type type;
+  int64_t length;
+  int64_t null_count;
+
+  const uint8_t* nulls;
+  const uint8_t* values;
+
+  const int32_t* offsets;
+} feather_array_t;
+
+typedef struct {
+  feather_array_t indices;
+  feather_array_t levels;
+  int ordered;
+} feather_category_t;
+
+typedef struct {
+  feather_array_t levels;
+  int ordered;
+} feather_category_data_t;
+
+typedef struct {
+  const char* timezone;
+  feather_time_unit unit;
+} feather_timestamp_data_t;
+
+typedef struct {
+  feather_time_unit unit;
+} feather_time_data_t;
+
+typedef struct {
+  feather_column_type type;
+  const char* name;
+  feather_array_t values;
+
+  void* data;
+  void* type_metadata;
+} feather_column_t;
+
+feather_status
+feather_column_free(feather_column_t* self);
+
+/*
+ *************************************************
+  TableWriter C API
+ *************************************************
+*/
+
+typedef void feather_writer_t;
+
+feather_status
+feather_writer_open_file(const char* path, feather_writer_t** out);
+
+void
+feather_writer_set_num_rows(feather_writer_t* self, int64_t num_rows);
+
+/* Write primitive array */
+feather_status
+feather_writer_append_plain(feather_writer_t* self, const char* name,
+    feather_array_t* values);
+
+feather_status
+feather_writer_append_category(feather_writer_t* self, const char* name,
+    feather_array_t* values, feather_array_t* levels, int ordered);
+
+feather_status
+feather_writer_append_timestamp(feather_writer_t* self, const char* name,
+    feather_array_t* values, const char* timezone,
+    feather_time_unit unit);
+
+feather_status
+feather_writer_append_time(feather_writer_t* self, const char* name,
+    feather_array_t* values, feather_time_unit unit);
+
+feather_status
+feather_writer_append_date(feather_writer_t* self, const char* name,
+    feather_array_t* values);
+
+/* Write file metadata and footer */
+feather_status
+feather_writer_close(feather_writer_t* self);
+
+/* Close file if any, and deallocate TableWriter */
+feather_status
+feather_writer_free(feather_writer_t* self);
+
+/*
+ *************************************************
+  TableReader C API
+ *************************************************
+*/
+
+typedef void feather_reader_t;
+
+feather_status
+feather_reader_open_file(const char* path, feather_reader_t** out);
+
+int64_t
+feather_reader_num_rows(feather_reader_t* self);
+
+int64_t
+feather_reader_num_columns(feather_reader_t* self);
+
+/*
+ * Retrieve the column metadata and data pointers from the file. Call
+ * feather_column_free when finished with the column.
+ */
+feather_status
+feather_reader_get_column(feather_reader_t* self, int i, feather_column_t* out);
+
+feather_status
+feather_reader_close(feather_reader_t* self);
+
+feather_status
+feather_reader_free(feather_reader_t* self);
+
+#ifdef __cplusplus
+#if 0 /* confuse emacs indentation */
+{
+#endif
+}
+#endif
+
+#endif /* FEATHER_FEATHER_C_H */
diff --git a/src/feather/metadata.cc b/src/feather/metadata.cc
index cd4480e..6b37c17 100644
--- a/src/feather/metadata.cc
+++ b/src/feather/metadata.cc
@@ -509,6 +509,8 @@ std::shared_ptr<Column> TimestampColumn::Make(const void* fbs_column) {
   // flatbuffer non-null
   if (tz != 0) {
     result->metadata_.timezone = tz->str();
+  } else {
+    result->metadata_.timezone = "";
   }
 
   return result;
diff --git a/src/feather/reader.cc b/src/feather/reader.cc
index 540233c..334aa27 100644
--- a/src/feather/reader.cc
+++ b/src/feather/reader.cc
@@ -129,16 +129,17 @@ Status TableReader::GetPrimitiveArray(const ArrayMetadata& meta,
 }
 
 Status TableReader::GetPrimitive(std::shared_ptr<metadata::Column> col_meta,
-    std::shared_ptr<Column>* out) const {
+    std::unique_ptr<Column>* out) const {
   auto values_meta = col_meta->values();
   PrimitiveArray values;
   RETURN_NOT_OK(GetPrimitiveArray(values_meta, &values));
-  *out = std::make_shared<Column>(col_meta->type(), col_meta, values);
+
+  out->reset(new Column(col_meta->type(), col_meta, values));
   return Status::OK();
 }
 
 Status TableReader::GetCategory(std::shared_ptr<metadata::Column> col_meta,
-    std::shared_ptr<Column>* out) const {
+    std::unique_ptr<Column>* out) const {
   PrimitiveArray values, levels;
   auto cat_meta = static_cast<metadata::CategoryColumn*>(col_meta.get());
 
@@ -147,35 +148,38 @@ Status TableReader::GetCategory(std::shared_ptr<metadata::Column> col_meta,
 
   auto levels_meta = cat_meta->levels();
   RETURN_NOT_OK(GetPrimitiveArray(levels_meta, &levels));
-  *out = std::make_shared<CategoryColumn>(col_meta, values, levels,
-    cat_meta->ordered());
+
+  out->reset(new CategoryColumn(col_meta, values, levels,
+      cat_meta->ordered()));
 
   return Status::OK();
 }
 
 Status TableReader::GetTimestamp(std::shared_ptr<metadata::Column> col_meta,
-    std::shared_ptr<Column>* out) const {
+    std::unique_ptr<Column>* out) const {
   PrimitiveArray values;
   auto ts_meta = static_cast<metadata::TimestampColumn*>(col_meta.get());
 
   auto values_meta = ts_meta->values();
   RETURN_NOT_OK(GetPrimitiveArray(values_meta, &values));
-  *out = std::make_shared<TimestampColumn>(col_meta, values);
+
+  out->reset(new TimestampColumn(col_meta, values));
   return Status::OK();
 }
 
 Status TableReader::GetTime(std::shared_ptr<metadata::Column> col_meta,
-    std::shared_ptr<Column>* out) const {
+    std::unique_ptr<Column>* out) const {
   PrimitiveArray values;
   auto time_meta = static_cast<metadata::TimeColumn*>(col_meta.get());
 
   auto values_meta = time_meta->values();
   RETURN_NOT_OK(GetPrimitiveArray(values_meta, &values));
-  *out = std::make_shared<TimeColumn>(col_meta, values);
+
+  out->reset(new TimeColumn(col_meta, values));
   return Status::OK();
 }
 
-Status TableReader::GetColumn(int i, std::shared_ptr<Column>* out) const {
+Status TableReader::GetColumn(int i, std::unique_ptr<Column>* out) const {
   std::shared_ptr<metadata::Column> col_meta = metadata_.GetColumn(i);
   switch (col_meta->type()) {
     case ColumnType::PRIMITIVE:
@@ -194,7 +198,7 @@ Status TableReader::GetColumn(int i, std::shared_ptr<Column>* out) const {
       RETURN_NOT_OK(GetTime(col_meta, out));
       break;
     default:
-      *out = std::shared_ptr<Column>(nullptr);
+      out->reset(nullptr);
       break;
   }
   return Status::OK();
diff --git a/src/feather/reader.h b/src/feather/reader.h
index 939fd88..cc8bc9a 100644
--- a/src/feather/reader.h
+++ b/src/feather/reader.h
@@ -32,7 +32,9 @@ class Column {
       const PrimitiveArray& values) :
       type_(type),
       metadata_(metadata),
-      values_(values) {}
+      values_(values) {
+    name_ = metadata_->name();
+  }
 
   const PrimitiveArray& values() const {
     return values_;
@@ -46,12 +48,13 @@ class Column {
     return metadata_;
   }
 
-  std::string name() const {
-    return metadata_->name();
+  const std::string& name() const {
+    return name_;
   }
 
  protected:
   ColumnType::type type_;
+  std::string name_;
   std::shared_ptr<metadata::Column> metadata_;
   PrimitiveArray values_;
 };
@@ -88,18 +91,20 @@ class TimestampColumn : public Column {
       const PrimitiveArray& values) :
       Column(ColumnType::TIMESTAMP, metadata, values)  {
     timestamp_meta_ = static_cast<const metadata::TimestampColumn*>(metadata.get());
+    timezone_ = timestamp_meta_->timezone();
   }
 
   TimeUnit::type unit() const {
     return timestamp_meta_->unit();
   }
 
-  std::string timezone() const {
-    return timestamp_meta_->timezone();
+  const std::string& timezone() const {
+    return timezone_;
   }
 
  private:
   const metadata::TimestampColumn* timestamp_meta_;
+  std::string timezone_;
 };
 
 class DateColumn : public Column {
@@ -148,22 +153,22 @@ class TableReader {
   int64_t num_rows() const;
   int64_t num_columns() const;
 
-  Status GetColumn(int i, std::shared_ptr<Column>* out) const;
+  Status GetColumn(int i, std::unique_ptr<Column>* out) const;
 
  private:
   Status GetPrimitive(std::shared_ptr<metadata::Column> col_meta,
-      std::shared_ptr<Column>* out) const;
+      std::unique_ptr<Column>* out) const;
   Status GetCategory(std::shared_ptr<metadata::Column> col_meta,
-      std::shared_ptr<Column>* out) const;
+      std::unique_ptr<Column>* out) const;
 
   Status GetTimestamp(std::shared_ptr<metadata::Column> col_meta,
-      std::shared_ptr<Column>* out) const;
+      std::unique_ptr<Column>* out) const;
 
   Status GetTime(std::shared_ptr<metadata::Column> col_meta,
-      std::shared_ptr<Column>* out) const;
+      std::unique_ptr<Column>* out) const;
 
   Status GetDate(std::shared_ptr<metadata::Column> col_meta,
-      std::shared_ptr<Column>* out) const;
+      std::unique_ptr<Column>* out) const;
 
   // Retrieve a primitive array from the data source
   //
diff --git a/src/feather/status.h b/src/feather/status.h
index c971752..88fba0f 100644
--- a/src/feather/status.h
+++ b/src/feather/status.h
@@ -77,6 +77,7 @@ class Status {
   bool IsKeyError() const { return code() == StatusCode::KeyError; }
   bool IsIOError() const { return code() == StatusCode::IOError; }
   bool IsInvalid() const { return code() == StatusCode::Invalid; }
+  bool IsNotImplemented() const { return code() == StatusCode::NotImplemented; }
 
   // Return a string representation of this status suitable for printing.
   // Returns the string "OK" for success.
diff --git a/src/feather/tests/c-api-test.cc b/src/feather/tests/c-api-test.cc
new file mode 100644
index 0000000..8d21cd2
--- /dev/null
+++ b/src/feather/tests/c-api-test.cc
@@ -0,0 +1,194 @@
+// Copyright 2016 Feather Developers
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstdio>
+#include <exception>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "feather/common.h"
+#include "feather/feather-c.h"
+#include "feather/tests/test-common.h"
+#include "feather/types.h"
+
+#define ASSERT_CFEATHER_OK(s) do {              \
+    feather_status _s = (s);                    \
+    ASSERT_EQ(FEATHER_OK, _s);                  \
+  } while (0);
+
+namespace feather {
+
+class TestCAPI : public ::testing::Test {
+ public:
+  virtual void TearDown() {
+    for (const std::string& path : tmp_paths_) {
+      try {
+        std::remove(path.c_str());
+      } catch (const std::exception& e) {}
+    }
+  }
+
+  void OpenWriter(const std::string& path) {
+    const char* c_path = path.c_str();
+    tmp_paths_.push_back(path);
+
+    ASSERT_CFEATHER_OK(feather_writer_open_file(c_path, &writer_));
+  }
+
+  void CloseWriter() {
+    ASSERT_CFEATHER_OK(feather_writer_close(writer_));
+    ASSERT_CFEATHER_OK(feather_writer_free(writer_));
+  }
+
+  void OpenReader(const std::string& path) {
+    ASSERT_CFEATHER_OK(feather_reader_open_file(path.c_str(), &reader_));
+  }
+
+  void CloseReader() {
+    ASSERT_CFEATHER_OK(feather_reader_close(reader_));
+    ASSERT_CFEATHER_OK(feather_reader_free(reader_));
+  }
+
+ protected:
+  std::vector<std::string> tmp_paths_;
+
+  feather_writer_t* writer_;
+  feather_reader_t* reader_;
+};
+
+TEST_F(TestCAPI, FileNotExist) {
+  feather_status s;
+  feather_reader_t* reader;
+
+  const char* path = "file-not-exist.feather";
+
+  s = feather_reader_open_file(path, &reader);
+  ASSERT_EQ(FEATHER_IO_ERROR, s);
+}
+
+TEST_F(TestCAPI, WriteNumRows) {
+  const int num_rows = 1000;
+
+  std::string path("test-cfeather-write-num-rows");
+
+  OpenWriter(path);
+  feather_writer_set_num_rows(writer_, num_rows);
+  CloseWriter();
+
+  OpenReader(path);
+  ASSERT_EQ(num_rows, feather_reader_num_rows(reader_));
+  ASSERT_EQ(0, feather_reader_num_columns(reader_));
+  CloseReader();
+}
+
+void MakePrimitive(feather_type type,
+    int64_t length, int64_t null_count,
+    const uint8_t* nulls, const uint8_t* values,
+    const int32_t* offsets, feather_array_t* out) {
+  out->type = type;
+  out->length = length;
+  out->null_count = null_count;
+  out->nulls = nulls;
+  out->values = values;
+  out->offsets = offsets;
+}
+
+static PrimitiveType::type ToFeatherType(feather_type ctype) {
+  return static_cast<PrimitiveType::type>(static_cast<int>(ctype));
... 141 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-feather-format.git



More information about the Python-modules-commits mailing list