Skip to content

Commit

Permalink
Move PrimitiveType::ToString template back to type.h
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Mar 7, 2016
1 parent b5b5b82 commit 731544a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
9 changes: 0 additions & 9 deletions cpp/src/arrow/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ std::string Field::ToString() const {

DataType::~DataType() {}

template <typename Derived>
inline std::string PrimitiveType<Derived>::ToString() const {
std::string result(static_cast<const Derived*>(this)->name());
if (!nullable) {
result.append(" not null");
}
return result;
}

StringType::StringType(bool nullable)
: DataType(LogicalType::STRING, nullable) {}

Expand Down
9 changes: 9 additions & 0 deletions cpp/src/arrow/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ struct PrimitiveType : public DataType {
std::string ToString() const override;
};

template <typename Derived>
inline std::string PrimitiveType<Derived>::ToString() const {
std::string result(static_cast<const Derived*>(this)->name());
if (!nullable) {
result.append(" not null");
}
return result;
}

#define PRIMITIVE_DECL(TYPENAME, C_TYPE, ENUM, SIZE, NAME) \
typedef C_TYPE c_type; \
static constexpr LogicalType::type type_enum = LogicalType::ENUM; \
Expand Down
3 changes: 2 additions & 1 deletion python/arrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# flake8: noqa

from arrow.array import Array, from_list
from arrow.schema import (bool_, int8, int16, int32, int64,
from arrow.schema import (null, bool_,
int8, int16, int32, int64,
uint8, uint16, uint32, uint64,
float_, double, string,
list_, struct, field,
Expand Down
5 changes: 5 additions & 0 deletions python/arrow/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ cdef class Array:
return self.array.length()


cdef class NullArray(Array):
pass


cdef class BooleanArray(Array):
pass

Expand Down Expand Up @@ -88,6 +92,7 @@ cdef class StringArray(Array):


cdef dict _array_classes = {
LogicalType_NA: NullArray,
LogicalType_BOOL: BooleanArray,
LogicalType_INT64: Int64Array,
LogicalType_LIST: ListArray,
Expand Down
2 changes: 2 additions & 0 deletions python/arrow/includes/arrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ from arrow.includes.common cimport *
cdef extern from "arrow/api.h" namespace "arrow" nogil:

enum LogicalType" arrow::LogicalType::type":
LogicalType_NA" arrow::LogicalType::NA"

LogicalType_BOOL" arrow::LogicalType::BOOL"

LogicalType_UINT8" arrow::LogicalType::UINT8"
Expand Down
3 changes: 3 additions & 0 deletions python/arrow/schema.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ cdef DataType primitive_type(LogicalType type, bint nullable=True):
def field(name, type):
return Field(name, type)

def null():
return primitive_type(LogicalType_NA)

def bool_(c_bool nullable=True):
return primitive_type(LogicalType_BOOL, nullable)

Expand Down
5 changes: 5 additions & 0 deletions python/arrow/tests/test_convert_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class TestConvertList(unittest.TestCase):
def test_boolean(self):
pass

def test_empty_list(self):
arr = arrow.from_list([])
assert len(arr) == 0
assert arr.type == arrow.null()

def test_integer(self):
arr = arrow.from_list([1, 2, 3])
assert len(arr) == 3
Expand Down
8 changes: 8 additions & 0 deletions python/src/pyarrow/adapters/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ Status ConvertPySequence(PyObject* obj, std::shared_ptr<arrow::Array>* out) {
int64_t size;
RETURN_NOT_OK(InferArrowType(obj, &size, &type));

// Handle NA / NullType case
if (type->type == LogicalType::NA) {
out->reset(new arrow::Array(type, size));
return Status::OK();
}

std::shared_ptr<SeqConverter> converter = GetConverter(type);
if (converter == nullptr) {
std::stringstream ss;
Expand All @@ -244,6 +250,8 @@ Status ConvertPySequence(PyObject* obj, std::shared_ptr<arrow::Array>* out) {

RETURN_NOT_OK(converter->AppendData(obj));

*out = builder->Finish();

return Status::OK();
}

Expand Down

0 comments on commit 731544a

Please sign in to comment.