Skip to content

Commit

Permalink
Add Status::ToString impls. Unit test stub
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Mar 7, 2016
1 parent 4e206fc commit 3a774fb
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cpp/src/arrow/util/status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,44 @@ const char* Status::CopyState(const char* state) {
return result;
}

std::string Status::CodeAsString() const {
if (state_ == NULL) {
return "OK";
}

const char* type;
switch (code()) {
case StatusCode::OK:
type = "OK";
break;
case StatusCode::OutOfMemory:
type = "Out of memory";
break;
case StatusCode::KeyError:
type = "Key error";
break;
case StatusCode::Invalid:
type = "Invalid";
break;
case StatusCode::NotImplemented:
type = "NotImplemented";
break;
}
return std::string(type);
}

std::string Status::ToString() const {
std::string result(CodeAsString());
if (state_ == NULL) {
return result;
}

result.append(": ");

uint32_t length;
memcpy(&length, state_, sizeof(length));
result.append(reinterpret_cast<const char*>(state_ + 7), length);
return result;
}

} // namespace arrow
1 change: 1 addition & 0 deletions python/arrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# flake8: noqa

from arrow.array import Array, from_list
from arrow.schema import (bool_, int8, int16, int32, int64,
uint8, uint16, uint32, uint64,
float_, double, string,
Expand Down
5 changes: 5 additions & 0 deletions python/arrow/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ cdef class Array:
cdef init(self, const shared_ptr[CArray]& sp_array):
self.sp_array = sp_array

property null_count:

def __get__(self):
return self.sp_array.get().null_count()

def __len__(self):
return self.array.length()

Expand Down
54 changes: 54 additions & 0 deletions python/src/pyarrow/status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "pyarrow/status.h"

#include <assert.h>
#include <cstdint>
#include <cstring>

namespace pyarrow {

Expand All @@ -35,4 +37,56 @@ const char* Status::CopyState(const char* state) {
return result;
}

std::string Status::CodeAsString() const {
if (state_ == NULL) {
return "OK";
}

const char* type;
switch (code()) {
case StatusCode::OK:
type = "OK";
break;
case StatusCode::OutOfMemory:
type = "Out of memory";
break;
case StatusCode::KeyError:
type = "Key error";
break;
case StatusCode::TypeError:
type = "Value error";
break;
case StatusCode::ValueError:
type = "Value error";
break;
case StatusCode::IOError:
type = "IO error";
break;
case StatusCode::NotImplemented:
type = "Not implemented";
break;
case StatusCode::ArrowError:
type = "Arrow C++ error";
break;
case StatusCode::UnknownError:
type = "Unknown error";
break;
}
return std::string(type);
}

std::string Status::ToString() const {
std::string result(CodeAsString());
if (state_ == NULL) {
return result;
}

result.append(": ");

uint32_t length;
memcpy(&length, state_, sizeof(length));
result.append(reinterpret_cast<const char*>(state_ + 7), length);
return result;
}

} // namespace pyarrow

0 comments on commit 3a774fb

Please sign in to comment.