| 385 | |
| 386 | ############################################################################## |
| 387 | class TestMRecordsImport: |
| 388 | |
| 389 | _a = ma.array([1, 2, 3], mask=[0, 0, 1], dtype=int) |
| 390 | _b = ma.array([1.1, 2.2, 3.3], mask=[0, 0, 1], dtype=float) |
| 391 | _c = ma.array([b'one', b'two', b'three'], |
| 392 | mask=[0, 0, 1], dtype='|S8') |
| 393 | ddtype = [('a', int), ('b', float), ('c', '|S8')] |
| 394 | mrec = fromarrays([_a, _b, _c], dtype=ddtype, |
| 395 | fill_value=(b'99999', b'99999.', |
| 396 | b'N/A')) |
| 397 | nrec = recfromarrays((_a._data, _b._data, _c._data), dtype=ddtype) |
| 398 | data = (mrec, nrec, ddtype) |
| 399 | |
| 400 | def test_fromarrays(self): |
| 401 | _a = ma.array([1, 2, 3], mask=[0, 0, 1], dtype=int) |
| 402 | _b = ma.array([1.1, 2.2, 3.3], mask=[0, 0, 1], dtype=float) |
| 403 | _c = ma.array(['one', 'two', 'three'], mask=[0, 0, 1], dtype='|S8') |
| 404 | (mrec, nrec, _) = self.data |
| 405 | for (f, l) in zip(('a', 'b', 'c'), (_a, _b, _c)): |
| 406 | assert_equal(getattr(mrec, f)._mask, l._mask) |
| 407 | # One record only |
| 408 | _x = ma.array([1, 1.1, 'one'], mask=[1, 0, 0], dtype=object) |
| 409 | assert_equal_records(fromarrays(_x, dtype=mrec.dtype), mrec[0]) |
| 410 | |
| 411 | def test_fromrecords(self): |
| 412 | # Test construction from records. |
| 413 | (mrec, nrec, ddtype) = self.data |
| 414 | #...... |
| 415 | palist = [(1, 'abc', 3.7000002861022949, 0), |
| 416 | (2, 'xy', 6.6999998092651367, 1), |
| 417 | (0, ' ', 0.40000000596046448, 0)] |
| 418 | pa = recfromrecords(palist, names='c1, c2, c3, c4') |
| 419 | mpa = fromrecords(palist, names='c1, c2, c3, c4') |
| 420 | assert_equal_records(pa, mpa) |
| 421 | #..... |
| 422 | _mrec = fromrecords(nrec) |
| 423 | assert_equal(_mrec.dtype, mrec.dtype) |
| 424 | for field in _mrec.dtype.names: |
| 425 | assert_equal(getattr(_mrec, field), getattr(mrec._data, field)) |
| 426 | |
| 427 | _mrec = fromrecords(nrec.tolist(), names='c1,c2,c3') |
| 428 | assert_equal(_mrec.dtype, [('c1', int), ('c2', float), ('c3', '|S5')]) |
| 429 | for (f, n) in zip(('c1', 'c2', 'c3'), ('a', 'b', 'c')): |
| 430 | assert_equal(getattr(_mrec, f), getattr(mrec._data, n)) |
| 431 | |
| 432 | _mrec = fromrecords(mrec) |
| 433 | assert_equal(_mrec.dtype, mrec.dtype) |
| 434 | assert_equal_records(_mrec._data, mrec.filled()) |
| 435 | assert_equal_records(_mrec._mask, mrec._mask) |
| 436 | |
| 437 | def test_fromrecords_wmask(self): |
| 438 | # Tests construction from records w/ mask. |
| 439 | (mrec, nrec, ddtype) = self.data |
| 440 | |
| 441 | _mrec = fromrecords(nrec.tolist(), dtype=ddtype, mask=[0, 1, 0,]) |
| 442 | assert_equal_records(_mrec._data, mrec._data) |
| 443 | assert_equal(_mrec._mask.tolist(), [(0, 0, 0), (1, 1, 1), (0, 0, 0)]) |
| 444 |
nothing calls this directly
no test coverage detected