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