ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Functions
test_adc_types Namespace Reference

Functions

 add2 (x, name, value)
 
 add (x, name, value)
 
 test_tolist_odd_types ()
 
 test_get_common_py_type ()
 
 main ()
 

Function Documentation

◆ add()

test_adc_types.add (   x,
  name,
  value 
)
48def add(x, name, value):
49 print(name)
50 print(value)
51 print(type(value))
52 print("")
53

◆ add2()

test_adc_types.add2 (   x,
  name,
  value 
)
13def add2(x, name, value):
14 if value is None:
15 return
16 if isinstance(value, range):
17 pass
18 if type(value) == int:
20 pass
21 #store as cp_number_str
22 pass
23 if type(value) == str:
24 pass # subtypes detection?
25 if type(value) == bool:
26 pass
27 if type(value) == float:
28 pass
29 if type(value) == complex:
30 pass
31 if type(value) == decimal.Decimal:
32 pass
33 if type(value) in (list, tuple, set, frozenset):
34 pass
35 if type(value).__module__ == numpy.__name__:
36 print("numpy")
37 if isinstance(value, numpy.ndarray):
38 print(f"class: {value.__class__.__name__}")
39 print(f"type: {type(value)}")
40 print(f"shape: {value.shape}")
41 print(f"size: {value.itemsize}")
42 print(f"dtype: {value.dtype}")
43 print(f"dtypedir: {dir(value.dtype)}")
44 print("")
45 pass
46
47# test/debugging code
bool fits_int64(int v)
Definition adc_types.py:506

◆ main()

test_adc_types.main ( )
116def main():
117 y="""
118str
119range
120dict
121bytes
122bytearray
123"""
124 print(sys.float_info)
125 print(sys.int_info)
126 int64_max_value = numpy.iinfo(numpy.int64).max
127 print("imax")
128 print(int64_max_value)
129 uint64_max_value = numpy.iinfo(numpy.uint64).max
130 print("umax")
131 print(uint64_max_value)
132 int64_min_value = numpy.iinfo(numpy.int64).min
133 print("imin")
134 print(int64_min_value)
135 uint64_min_value = numpy.iinfo(numpy.uint64).min
136 print("umin")
137 print(uint64_min_value)
138 add(0, "str","str")
139 add(0, "list",["a",2.0,"1"])
140 add(0, "tuple",("a",2.0,"1"))
141 add(0, "range",(5))
142 add(0, "dict",{})
143 add(0, "dict2",{0:0 })
144 add(0, "set",{ 1,2,3 })
145 add(0, "fset", frozenset({"apple", "banana", "cherry"}) )
146 add(0, "bool",True)
147 add(0, "bytes", '123')
148 add(0, "bytearray", b'123')
149 add(0, "none", None)
150 add(0, "int", 123)
151 add(0, "int10", 123123123123123)
152 add(0, "int20", 12312312312312312312)
153 add(0, "int36", 123123123123123123121231231231231231)
154 add(0, "int67", 1231231231231231231212312312312312313412312312312312312312321313213)
155 add(0, "decimal", decimal.Decimal('1.2342342234324234234243242'))
156 add(0, "float", 1.345)
157 add(0, "floatq", 1.34512312312312312312312312312)
158 add(0, "complex", complex(1.1,2.2))
159 add(0, "icomplex", complex(1,2))
160 zr = numpy.zeros(shape = (2,3, 9))
161 add2(0,"numpy", zr)
162 zr = numpy.zeros(shape = (2,3, 9), dtype=numpy.bool)
163 add2(0,"numpy", zr)
164 r = numpy.zeros(shape = (2,3, 9), dtype=numpy.uint64)
165 add2(0,"numpy", r)
166 test_get_common_py_type()
167 test_tolist_odd_types()
168 print("done")
169

◆ test_get_common_py_type()

test_adc_types.test_get_common_py_type ( )
96def test_get_common_py_type():
97 __test_get_common_py_type("ascalar", 1, 0, 1, 1, int)
98 __test_get_common_py_type("aset", {-1, 2, 3}, 1, 1, 3, int)
99 __test_get_common_py_type("alist", [1.0, 2.0, 3.0], 1, 0, 0, float)
100 __test_get_common_py_type("atuple", (-1, 2, 3), 1, 1, 3, int)
101
102 __test_get_common_py_type("aset2", {frozenset([-1, 2, 3]),frozenset([-3,4,5])},
103 2, 1, 5, int)
104 __test_get_common_py_type("alist2", [[1, 2, 3],[6,7]], 2, 1, 7, int)
105 __test_get_common_py_type("atuple2", [(-1, 2, 3),[8,-9]], 2, -9, 8, int)
106
107 __test_get_common_py_type("badset", {1, 2, 3.0}, 1, 1, 3, int)
108 __test_get_common_py_type("badlist", [1, 2, 3.0], 1, 1, 3, int)
109 __test_get_common_py_type("badtuple", (1, 2, 3.0), 1, 1, 3, int)
110
111 __test_get_common_py_type("badset2", {frozenset([-1, 2, 3]),frozenset([-3,4,5.0])},
112 2, 1, 5, int)
113 __test_get_common_py_type("badlist2", [[1, 2, 3],[6,7.0]], 2, 1, 7, int)
114 __test_get_common_py_type("badtuple2", [(-1, 2, 3),[8,-9.0]], 2, -9, 8, int)
115

◆ test_tolist_odd_types()

test_adc_types.test_tolist_odd_types ( )
67def test_tolist_odd_types():
68 import pprint
69 print('uint64')
70 y = numpy.iinfo(numpy.uint64).max
71 r = numpy.full((2,3,4), y, numpy.uint64)
73 pprint.pprint(x)
74
75 y = complex(numpy.finfo(numpy.float32).max / 2.0, numpy.finfo(numpy.float32).max / 4.0 )
76 print(f'c_f_32{y}')
77 r = numpy.full((2,3,4), y, numpy.complex64)
79 pprint.pprint(x)
80
81 y = complex(numpy.finfo(numpy.float64).max / 2.0, numpy.finfo(numpy.float64).max / 4.0 )
82 print(f'c_f_64{y}')
83 r = numpy.full((2,3,4), y, dtype=numpy.complex128)
85 pprint.pprint(x)
86
87 # ext_str should mostly fit in float80 as well, possibly truncating mantissa
88 ext_str = "1.23456789012345678901234567890123456e+4000"
89 f128 = numpy.float128(ext_str)
90 print(f'c_f_128{f128}')
91 r = numpy.full((2,3,4), f128, dtype=numpy.complex256)
92 r.imag = r.real / 2.0
94 pprint.pprint(x)
95
get_list_format_numpy(numpy.ndarray a)
build a nested list out of numpy array, accounting for int must fit in int64 or be string encoded and...
Definition adc_types.py:316