Skip to content

Commit 088d7f2

Browse files
committed
Merge pull request #612 from skrah/type_properties2
Use the new type properties from libdynd.
2 parents d37e243 + 18bc571 commit 088d7f2

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

dynd/cpp/array.pxd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from libcpp cimport bool
44
from libcpp.map cimport map
55
from libcpp.string cimport string
66
from libcpp.vector cimport vector
7-
from .type cimport type
7+
from .type cimport type, property_t
88

99
cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil:
1010

@@ -36,6 +36,9 @@ cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil:
3636

3737
array view_scalars(type&) except +translate_exception
3838

39+
@staticmethod
40+
array from_type_property(const property_t &) except +translate_exception
41+
3942
bool is_null()
4043

4144
void assign(array &) except +translate_exception

dynd/cpp/type.pxd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from libcpp cimport bool
22
from libcpp.map cimport map
33
from libcpp.string cimport string
4+
from libcpp.pair cimport pair
45

56
from .types.type_id cimport *
67

78
from ..config cimport translate_exception
8-
from .array cimport array
9-
from .callable cimport callable
109

1110
cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil:
11+
cdef cppclass type
12+
ctypedef pair[type, const char *] property_t
13+
1214
cdef cppclass type:
1315
type()
1416
type(type_id_t) except +translate_exception
@@ -20,7 +22,7 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil:
2022
size_t get_arrmeta_size()
2123
type get_canonical_type()
2224

23-
map[string, callable] get_properties()
25+
map[string, property_t] get_properties()
2426

2527
bool is_builtin()
2628
bool is_null()
@@ -35,5 +37,3 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil:
3537

3638
type make_type[T]() except +translate_exception
3739

38-
cdef extern from 'dynd/type.hpp' namespace 'dynd' nogil:
39-
void get_builtin_type_dynamic_array_properties(type_id_t, map[string, callable] &)

dynd/nd/array.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from ..cpp.array cimport (groupby as dynd_groupby, array_add, array_subtract,
1717
array_multiply, array_divide, empty as cpp_empty,
1818
dtyped_zeros, dtyped_ones, dtyped_empty)
1919
from ..cpp.callable_registry cimport callable_registry
20-
from ..cpp.type cimport get_builtin_type_dynamic_array_properties, make_type
20+
from ..cpp.type cimport make_type
2121
from ..cpp.types.categorical_type cimport dynd_make_categorical_type
2222
from ..cpp.types.datashape_formatter cimport format_datashape as dynd_format_datashape
2323
from ..cpp.types.type_id cimport *

dynd/ndt/type.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from libc.stdint cimport (intptr_t, int8_t, int16_t, int32_t, int64_t,
66
from libcpp.map cimport map
77
from libcpp.string cimport string
88
from libcpp.vector cimport vector
9+
from libcpp.pair cimport pair
910
from libcpp cimport bool as cpp_bool
1011

1112
import datetime
@@ -35,6 +36,8 @@ from ..cpp.types.string_type cimport string_type
3536
from ..cpp.types.bytes_type cimport make as make_bytes_type
3637
from ..cpp.callable cimport callable as _callable
3738
from ..cpp.type cimport make_type
39+
from ..cpp.type cimport type as dynd_ndt_type
40+
from ..cpp.array cimport array as dynd_nd_array
3841
from ..cpp.complex cimport complex as dynd_complex
3942

4043
from ..config cimport translate_exception
@@ -228,13 +231,11 @@ cdef class type(object):
228231
if self.v.is_null():
229232
raise AttributeError(name)
230233

231-
cdef _callable p
232-
cdef map[string, _callable] properties = self.v.get_properties()
233-
p = properties[name]
234-
if (not p.is_null()):
235-
return dynd_nd_array_from_cpp(p(self.v))
234+
cdef pair[dynd_ndt_type, const char*] p = self.v.get_properties()[name]
235+
if p.first.is_null():
236+
raise AttributeError(name)
236237

237-
raise AttributeError(name)
238+
return dynd_nd_array_from_cpp(dynd_nd_array.from_type_property(p))
238239

239240
def __str__(self):
240241
return str(<char *>_type_str(self.v).c_str())

0 commit comments

Comments
 (0)