More fixes. Change TimeUnit to struct-based enum

This commit is contained in:
Wes McKinney committed 2017-04-16 01:00:11 -04:00
1 parent 2be93f0fed
commit 1e657ad878
13 files changed
+62 -113

No files matched your search

+3 -4
View File
@@ -17,10 +17,10 @@
#
# Sets COMPILER_FAMILY to 'clang' or 'gcc'
# Sets COMPILER_VERSION to the version
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -v
execute_process(COMMAND "${CMAKE_CXX_COMPILER}"
ERROR_VARIABLE COMPILER_VERSION_FULL)
message(INFO " ${COMPILER_VERSION_FULL}")
message(INFO " ${CMAKE_CXX_COMPILER_ID}")
message(INFO "Compiler version: ${COMPILER_VERSION_FULL}")
message(INFO "Compiler id: ${CMAKE_CXX_COMPILER_ID}")
string(TOLOWER "${COMPILER_VERSION_FULL}" COMPILER_VERSION_FULL_LOWER)
if(MSVC)
@@ -62,4 +62,3 @@ else()
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
endif()
message("Selected compiler ${COMPILER_FAMILY} ${COMPILER_VERSION}")
+8 -8
View File
@@ -75,7 +75,7 @@ struct ARROW_EXPORT CategoryMetadata {
};
struct ARROW_EXPORT TimestampMetadata {
TimeUnit unit;
TimeUnit::type unit;
// A timezone name known to the Olson timezone database. For display purposes
// because the actual data is all UTC
@@ -83,7 +83,7 @@ struct ARROW_EXPORT TimestampMetadata {
};
struct ARROW_EXPORT TimeMetadata {
TimeUnit unit;
TimeUnit::type unit;
};
static constexpr const char* kFeatherMagicBytes = "FEA1";
@@ -156,12 +156,12 @@ static inline flatbuffers::Offset<fbs::PrimitiveArray> GetPrimitiveArray(
array.length, array.null_count, array.total_bytes);
}
static inline fbs::TimeUnit ToFlatbufferEnum(TimeUnit unit) {
static inline fbs::TimeUnit ToFlatbufferEnum(TimeUnit::type unit) {
return static_cast<fbs::TimeUnit>(static_cast<int>(unit));
}
static inline TimeUnit FromFlatbufferEnum(fbs::TimeUnit unit) {
return static_cast<TimeUnit>(static_cast<int>(unit));
static inline TimeUnit::type FromFlatbufferEnum(fbs::TimeUnit unit) {
return static_cast<TimeUnit::type>(static_cast<int>(unit));
}
// Convert Feather enums to Flatbuffer enums
@@ -197,10 +197,10 @@ class ARROW_EXPORT ColumnBuilder {
void SetValues(const ArrayMetadata& values);
void SetUserMetadata(const std::string& data);
void SetCategory(const ArrayMetadata& levels, bool ordered = false);
void SetTimestamp(TimeUnit unit);
void SetTimestamp(TimeUnit unit, const std::string& timezone);
void SetTimestamp(TimeUnit::type unit);
void SetTimestamp(TimeUnit::type unit, const std::string& timezone);
void SetDate();
void SetTime(TimeUnit unit);
void SetTime(TimeUnit::type unit);
FBB& fbb();
private:
+4 -4
View File
@@ -184,12 +184,12 @@ void ColumnBuilder::SetCategory(const ArrayMetadata& levels, bool ordered) {
meta_category_.ordered = ordered;
}
void ColumnBuilder::SetTimestamp(TimeUnit unit) {
void ColumnBuilder::SetTimestamp(TimeUnit::type unit) {
type_ = ColumnType::TIMESTAMP;
meta_timestamp_.unit = unit;
}
void ColumnBuilder::SetTimestamp(TimeUnit unit, const std::string& timezone) {
void ColumnBuilder::SetTimestamp(TimeUnit::type unit, const std::string& timezone) {
SetTimestamp(unit);
meta_timestamp_.timezone = timezone;
}
@@ -198,7 +198,7 @@ void ColumnBuilder::SetDate() {
type_ = ColumnType::DATE;
}
void ColumnBuilder::SetTime(TimeUnit unit) {
void ColumnBuilder::SetTime(TimeUnit::type unit) {
type_ = ColumnType::TIME;
meta_time_.unit = unit;
}
@@ -279,7 +279,7 @@ class TableReader::TableReaderImpl {
}
case fbs::TypeMetadata_TimestampMetadata: {
auto meta = static_cast<const fbs::TimestampMetadata*>(metadata);
TimeUnit unit = FromFlatbufferEnum(meta->unit());
TimeUnit::type unit = FromFlatbufferEnum(meta->unit());
std::string tz;
// flatbuffer non-null
if (meta->timezone() != 0) {
+2 -2
View File
@@ -77,7 +77,7 @@ static std::string GetFloatingPrecisionName(FloatingPoint::Precision precision)
return "UNKNOWN";
}
static std::string GetTimeUnitName(TimeUnit unit) {
static std::string GetTimeUnitName(TimeUnit::type unit) {
switch (unit) {
case TimeUnit::SECOND:
return "SECOND";
@@ -645,7 +645,7 @@ static Status GetTimestamp(const RjObject& json_type, std::shared_ptr<DataType>*
std::string unit_str = json_unit->value.GetString();
TimeUnit unit;
TimeUnit::type unit;
if (unit_str == "SECOND") {
unit = TimeUnit::SECOND;
} else if (unit_str == "MILLISECOND") {
+4 -4
View File
@@ -188,7 +188,7 @@ static Status UnionToFlatBuffer(FBB& fbb, const std::shared_ptr<DataType>& type,
*offset = IntToFlatbuffer(fbb, BIT_WIDTH, IS_SIGNED); \
break;
static inline flatbuf::TimeUnit ToFlatbufferUnit(TimeUnit unit) {
static inline flatbuf::TimeUnit ToFlatbufferUnit(TimeUnit::type unit) {
switch (unit) {
case TimeUnit::SECOND:
return flatbuf::TimeUnit_SECOND;
@@ -204,7 +204,7 @@ static inline flatbuf::TimeUnit ToFlatbufferUnit(TimeUnit unit) {
return flatbuf::TimeUnit_MIN;
}
static inline TimeUnit FromFlatbufferUnit(flatbuf::TimeUnit unit) {
static inline TimeUnit::type FromFlatbufferUnit(flatbuf::TimeUnit unit) {
switch (unit) {
case flatbuf::TimeUnit_SECOND:
return TimeUnit::SECOND;
@@ -258,7 +258,7 @@ static Status TypeFromFlatbuffer(flatbuf::Type type, const void* type_data,
}
case flatbuf::Type_Time: {
auto time_type = static_cast<const flatbuf::Time*>(type_data);
TimeUnit unit = FromFlatbufferUnit(time_type->unit());
TimeUnit::type unit = FromFlatbufferUnit(time_type->unit());
int32_t bit_width = time_type->bitWidth();
switch (unit) {
case TimeUnit::SECOND:
@@ -279,7 +279,7 @@ static Status TypeFromFlatbuffer(flatbuf::Type type, const void* type_data,
}
case flatbuf::Type_Timestamp: {
auto ts_type = static_cast<const flatbuf::Timestamp*>(type_data);
TimeUnit unit = FromFlatbufferUnit(ts_type->unit());
TimeUnit::type unit = FromFlatbufferUnit(ts_type->unit());
if (ts_type->timezone() != 0 && ts_type->timezone()->Length() > 0) {
*out = timestamp(unit, ts_type->timezone()->str());
} else {
+1 -1
View File
@@ -166,7 +166,7 @@ Status NumPyDtypeToArrow(PyObject* dtype, std::shared_ptr<DataType>* out) {
case NPY_DATETIME: {
auto date_dtype =
reinterpret_cast<PyArray_DatetimeDTypeMetaData*>(descr->c_metadata);
TimeUnit unit;
TimeUnit::type unit;
switch (date_dtype->meta.base) {
case NPY_FR_s:
unit = TimeUnit::SECOND;
+7 -7
View File
@@ -134,10 +134,10 @@ std::string Date32Type::ToString() const {
// ----------------------------------------------------------------------
// Time types
TimeType::TimeType(Type::type type_id, TimeUnit unit)
TimeType::TimeType(Type::type type_id, TimeUnit::type unit)
: FixedWidthType(type_id), unit_(unit) {}
Time32Type::Time32Type(TimeUnit unit) : TimeType(Type::TIME32, unit) {
Time32Type::Time32Type(TimeUnit::type unit) : TimeType(Type::TIME32, unit) {
DCHECK(unit == TimeUnit::SECOND || unit == TimeUnit::MILLI)
<< "Must be seconds or milliseconds";
}
@@ -148,7 +148,7 @@ std::string Time32Type::ToString() const {
return ss.str();
}
Time64Type::Time64Type(TimeUnit unit) : TimeType(Type::TIME64, unit) {
Time64Type::Time64Type(TimeUnit::type unit) : TimeType(Type::TIME64, unit) {
DCHECK(unit == TimeUnit::MICRO || unit == TimeUnit::NANO)
<< "Must be microseconds or nanoseconds";
}
@@ -338,19 +338,19 @@ std::shared_ptr<DataType> fixed_size_binary(int32_t byte_width) {
return std::make_shared<FixedSizeBinaryType>(byte_width);
}
std::shared_ptr<DataType> timestamp(TimeUnit unit) {
std::shared_ptr<DataType> timestamp(TimeUnit::type unit) {
return std::make_shared<TimestampType>(unit);
}
std::shared_ptr<DataType> timestamp(TimeUnit unit, const std::string& timezone) {
std::shared_ptr<DataType> timestamp(TimeUnit::type unit, const std::string& timezone) {
return std::make_shared<TimestampType>(unit, timezone);
}
std::shared_ptr<DataType> time32(TimeUnit unit) {
std::shared_ptr<DataType> time32(TimeUnit::type unit) {
return std::make_shared<Time32Type>(unit);
}
std::shared_ptr<DataType> time64(TimeUnit unit) {
std::shared_ptr<DataType> time64(TimeUnit::type unit) {
return std::make_shared<Time64Type>(unit);
}
+17 -15
View File
@@ -538,9 +538,11 @@ class ARROW_EXPORT Date64Type : public DateType {
static std::string name() { return "date"; }
};
enum class TimeUnit : char { SECOND = 0, MILLI = 1, MICRO = 2, NANO = 3 };
struct TimeUnit {
enum type { SECOND = 0, MILLI = 1, MICRO = 2, NANO = 3 };
};
static inline std::ostream& operator<<(std::ostream& os, TimeUnit unit) {
static inline std::ostream& operator<<(std::ostream& os, TimeUnit::type unit) {
switch (unit) {
case TimeUnit::SECOND:
os << "s";
@@ -560,11 +562,11 @@ static inline std::ostream& operator<<(std::ostream& os, TimeUnit unit) {
class ARROW_EXPORT TimeType : public FixedWidthType {
public:
TimeUnit unit() const { return unit_; }
TimeUnit::type unit() const { return unit_; }
protected:
TimeType(Type::type type_id, TimeUnit unit);
TimeUnit unit_;
TimeType(Type::type type_id, TimeUnit::type unit);
TimeUnit::type unit_;
};
class ARROW_EXPORT Time32Type : public TimeType {
@@ -574,7 +576,7 @@ class ARROW_EXPORT Time32Type : public TimeType {
int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
explicit Time32Type(TimeUnit unit = TimeUnit::MILLI);
explicit Time32Type(TimeUnit::type unit = TimeUnit::MILLI);
Status Accept(TypeVisitor* visitor) const override;
std::string ToString() const override;
@@ -587,7 +589,7 @@ class ARROW_EXPORT Time64Type : public TimeType {
int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
explicit Time64Type(TimeUnit unit = TimeUnit::MILLI);
explicit Time64Type(TimeUnit::type unit = TimeUnit::MILLI);
Status Accept(TypeVisitor* visitor) const override;
std::string ToString() const override;
@@ -602,21 +604,21 @@ class ARROW_EXPORT TimestampType : public FixedWidthType {
int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
explicit TimestampType(TimeUnit unit = TimeUnit::MILLI)
explicit TimestampType(TimeUnit::type unit = TimeUnit::MILLI)
: FixedWidthType(Type::TIMESTAMP), unit_(unit) {}
explicit TimestampType(TimeUnit unit, const std::string& timezone)
explicit TimestampType(TimeUnit::type unit, const std::string& timezone)
: FixedWidthType(Type::TIMESTAMP), unit_(unit), timezone_(timezone) {}
Status Accept(TypeVisitor* visitor) const override;
std::string ToString() const override;
static std::string name() { return "timestamp"; }
TimeUnit unit() const { return unit_; }
TimeUnit::type unit() const { return unit_; }
const std::string& timezone() const { return timezone_; }
private:
TimeUnit unit_;
TimeUnit::type unit_;
std::string timezone_;
};
@@ -710,15 +712,15 @@ std::shared_ptr<DataType> ARROW_EXPORT fixed_size_binary(int32_t byte_width);
std::shared_ptr<DataType> ARROW_EXPORT list(const std::shared_ptr<Field>& value_type);
std::shared_ptr<DataType> ARROW_EXPORT list(const std::shared_ptr<DataType>& value_type);
std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit unit);
std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit::type unit);
std::shared_ptr<DataType> ARROW_EXPORT timestamp(
TimeUnit unit, const std::string& timezone);
TimeUnit::type unit, const std::string& timezone);
/// Unit can be either SECOND or MILLI
std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit unit);
std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit);
/// Unit can be either MICRO or NANO
std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit unit);
std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit::type unit);
std::shared_ptr<DataType> ARROW_EXPORT struct_(
const std::vector<std::shared_ptr<Field>>& fields);
+10 -12
View File
@@ -28,7 +28,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cpp/cmake_mod
include(CMakeParseArguments)
set(BUILD_SUPPORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../cpp/build-support)
set(BUILD_SUPPORT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/build-support")
# Allow "make install" to not depend on all targets.
#
@@ -58,10 +58,6 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
OFF)
endif()
if(NOT PYARROW_BUILD_TESTS)
set(NO_TESTS 1)
endif()
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
@@ -73,18 +69,19 @@ endif(CCACHE_FOUND)
############################################################
include(BuildUtils)
include(CompilerInfo)
include(SetupCxxFlags)
include(CompilerInfo)
# Add common flags
set(CMAKE_CXX_FLAGS "${CXX_COMMON_FLAGS} ${CMAKE_CXX_FLAGS}")
# Enable perf and other tools to work properly
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
# Suppress Cython warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
if (NOT MSVC)
# Enable perf and other tools to work properly
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
# Suppress Cython warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
endif()
if ("${COMPILER_FAMILY}" STREQUAL "clang")
# Using Clang with ccache causes a bunch of spurious warnings that are
@@ -146,9 +143,10 @@ endif()
#
# The gold linker is only for ELF binaries, which OSX doesn't use. We can
# just skip.
if (NOT APPLE)
if (NOT APPLE AND NOT MSVC)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE LINKER_OUTPUT)
endif ()
if (LINKER_OUTPUT MATCHES "gold")
if ("${PYARROW_LINK}" STREQUAL "d" AND
"${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
-48
View File
@@ -1,48 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
# Sets COMPILER_FAMILY to 'clang' or 'gcc'
# Sets COMPILER_VERSION to the version
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -v
ERROR_VARIABLE COMPILER_VERSION_FULL)
message(INFO " ${COMPILER_VERSION_FULL}")
# clang on Linux and Mac OS X before 10.9
if("${COMPILER_VERSION_FULL}" MATCHES ".*clang version.*")
set(COMPILER_FAMILY "clang")
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1"
COMPILER_VERSION "${COMPILER_VERSION_FULL}")
# clang on Mac OS X 10.9 and later
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*based on LLVM.*")
set(COMPILER_FAMILY "clang")
string(REGEX REPLACE ".*based on LLVM ([0-9]+\\.[0.9]+).*" "\\1"
COMPILER_VERSION "${COMPILER_VERSION_FULL}")
# clang on Mac OS X, XCode 7+. No version replacement is done
# because Apple no longer advertises the upstream LLVM version.
elseif("${COMPILER_VERSION_FULL}" MATCHES "clang-.*")
set(COMPILER_FAMILY "clang")
# gcc
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*gcc version.*")
set(COMPILER_FAMILY "gcc")
string(REGEX REPLACE ".*gcc version ([0-9\\.]+).*" "\\1"
COMPILER_VERSION "${COMPILER_VERSION_FULL}")
else()
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
endif()
message("Selected compiler ${COMPILER_FAMILY} ${COMPILER_VERSION}")
+5 -3
View File
@@ -122,9 +122,11 @@ function( compile_pyx _name pyx_target_name generated_files pyx_file)
endif()
set_source_files_properties( ${_generated_files} PROPERTIES GENERATED TRUE )
# Cython creates a lot of compiler warning detritus on clang
set_source_files_properties(${_generated_files} PROPERTIES
COMPILE_FLAGS -Wno-unused-function)
if (NOT WIN32)
# Cython creates a lot of compiler warning detritus on clang
set_source_files_properties(${_generated_files} PROPERTIES
COMPILE_FLAGS -Wno-unused-function)
endif()
set( ${generated_files} ${_generated_files} PARENT_SCOPE )
+1 -2
View File
@@ -26,8 +26,7 @@ from libcpp.vector cimport vector
from cpython cimport PyObject
cimport cpython
# This must be included for cerr and other things to work
cdef extern from "<iostream>":
cdef extern from "arrow/python/platform.h":
pass
cdef extern from "<Python.h>":
-3
View File
@@ -132,13 +132,10 @@ class build_ext(_build_ext):
return
static_lib_option = ''
build_tests_option = ''
cmake_options = [
'-DPYTHON_EXECUTABLE=%s' % sys.executable,
'-DPYARROW_BUILD_TESTS=off',
static_lib_option,
build_tests_option,
]
if self.with_parquet: