diff --git a/dynd/cpp/array.pxd b/dynd/cpp/array.pxd index 07511a2c..e76c988c 100644 --- a/dynd/cpp/array.pxd +++ b/dynd/cpp/array.pxd @@ -4,7 +4,7 @@ from libcpp cimport bool from libcpp.map cimport map from libcpp.string cimport string from libcpp.vector cimport vector -from .type cimport type +from .type cimport type, property_t cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil: @@ -36,6 +36,9 @@ cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil: array view_scalars(type&) except +translate_exception + @staticmethod + array from_type_property(const property_t &) except +translate_exception + bool is_null() void assign(array &) except +translate_exception diff --git a/dynd/cpp/type.pxd b/dynd/cpp/type.pxd index 75d0e31c..192cc97d 100644 --- a/dynd/cpp/type.pxd +++ b/dynd/cpp/type.pxd @@ -1,14 +1,16 @@ from libcpp cimport bool from libcpp.map cimport map from libcpp.string cimport string +from libcpp.pair cimport pair from .types.type_id cimport * from ..config cimport translate_exception -from .array cimport array -from .callable cimport callable cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil: + cdef cppclass type + ctypedef pair[type, const char *] property_t + cdef cppclass type: type() type(type_id_t) except +translate_exception @@ -20,7 +22,7 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil: size_t get_arrmeta_size() type get_canonical_type() - map[string, callable] get_properties() + map[string, property_t] get_properties() bool is_builtin() bool is_null() @@ -35,5 +37,3 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil: type make_type[T]() except +translate_exception -cdef extern from 'dynd/type.hpp' namespace 'dynd' nogil: - void get_builtin_type_dynamic_array_properties(type_id_t, map[string, callable] &) diff --git a/dynd/nd/array.pyx b/dynd/nd/array.pyx index cbf72d38..fc9eae00 100644 --- a/dynd/nd/array.pyx +++ b/dynd/nd/array.pyx @@ -17,7 +17,7 @@ from ..cpp.array cimport (groupby as dynd_groupby, array_add, array_subtract, array_multiply, array_divide, empty as cpp_empty, dtyped_zeros, dtyped_ones, dtyped_empty) from ..cpp.callable_registry cimport callable_registry -from ..cpp.type cimport get_builtin_type_dynamic_array_properties, make_type +from ..cpp.type cimport make_type from ..cpp.types.categorical_type cimport dynd_make_categorical_type from ..cpp.types.datashape_formatter cimport format_datashape as dynd_format_datashape from ..cpp.types.type_id cimport * diff --git a/dynd/ndt/type.pyx b/dynd/ndt/type.pyx index a6cedb35..9ed5470e 100644 --- a/dynd/ndt/type.pyx +++ b/dynd/ndt/type.pyx @@ -6,6 +6,7 @@ from libc.stdint cimport (intptr_t, int8_t, int16_t, int32_t, int64_t, from libcpp.map cimport map from libcpp.string cimport string from libcpp.vector cimport vector +from libcpp.pair cimport pair from libcpp cimport bool as cpp_bool import datetime @@ -35,6 +36,8 @@ from ..cpp.types.string_type cimport string_type from ..cpp.types.bytes_type cimport make as make_bytes_type from ..cpp.callable cimport callable as _callable from ..cpp.type cimport make_type +from ..cpp.type cimport type as dynd_ndt_type +from ..cpp.array cimport array as dynd_nd_array from ..cpp.complex cimport complex as dynd_complex from ..config cimport translate_exception @@ -228,13 +231,11 @@ cdef class type(object): if self.v.is_null(): raise AttributeError(name) - cdef _callable p - cdef map[string, _callable] properties = self.v.get_properties() - p = properties[name] - if (not p.is_null()): - return dynd_nd_array_from_cpp(p(self.v)) + cdef pair[dynd_ndt_type, const char*] p = self.v.get_properties()[name] + if p.first.is_null(): + raise AttributeError(name) - raise AttributeError(name) + return dynd_nd_array_from_cpp(dynd_nd_array.from_type_property(p)) def __str__(self): return str(_type_str(self.v).c_str())