Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dynd/cpp/array.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions dynd/cpp/type.pxd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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] &)
2 changes: 1 addition & 1 deletion dynd/nd/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
13 changes: 7 additions & 6 deletions dynd/ndt/type.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(<char *>_type_str(self.v).c_str())
Expand Down