|
16 | 16 | from ..tmpdirs import InTemporaryDirectory
|
17 | 17 |
|
18 | 18 | from ..volumeutils import (array_from_file,
|
19 |
| - array_to_file, |
20 |
| - calculate_scale, |
21 |
| - scale_min_max, |
22 |
| - can_cast, allopen, |
23 |
| - shape_zoom_affine, |
24 |
| - rec2dict) |
| 19 | + array_to_file, |
| 20 | + calculate_scale, |
| 21 | + scale_min_max, |
| 22 | + can_cast, allopen, |
| 23 | + make_dt_codes, |
| 24 | + native_code, |
| 25 | + shape_zoom_affine, |
| 26 | + rec2dict) |
25 | 27 |
|
26 | 28 | from numpy.testing import (assert_array_almost_equal,
|
27 | 29 | assert_array_equal)
|
@@ -288,3 +290,25 @@ def test_rec2dict():
|
288 | 290 | r = np.zeros((), dtype = [('x', 'i4'), ('s', 'S10')])
|
289 | 291 | d = rec2dict(r)
|
290 | 292 | yield assert_equal(d, {'x': 0, 's': ''})
|
| 293 | + |
| 294 | + |
| 295 | +def test_dtypes(): |
| 296 | + # numpy - at least up to 1.5.1 - has odd behavior for hashing - |
| 297 | + # specifically: |
| 298 | + # In [9]: hash(dtype('<f4')) == hash(dtype('<f4').newbyteorder('<')) |
| 299 | + # Out[9]: False |
| 300 | + # In [10]: dtype('<f4') == dtype('<f4').newbyteorder('<') |
| 301 | + # Out[10]: True |
| 302 | + # where '<' is the native byte order |
| 303 | + dt_defs = ((16, 'float32', np.float32),) |
| 304 | + dtr = make_dt_codes(dt_defs) |
| 305 | + # These of course should pass regardless of dtype |
| 306 | + assert_equal(dtr[np.float32], 16) |
| 307 | + assert_equal(dtr['float32'], 16) |
| 308 | + # These also pass despite dtype issue |
| 309 | + assert_equal(dtr[np.dtype(np.float32)], 16) |
| 310 | + assert_equal(dtr[np.dtype('f4')], 16) |
| 311 | + assert_equal(dtr[np.dtype('f4').newbyteorder('S')], 16) |
| 312 | + # But this one used to fail |
| 313 | + assert_equal(dtr[np.dtype('f4').newbyteorder(native_code)], 16) |
| 314 | + |
0 commit comments