From 22d96096bf7d5fb199ca80f2fcd04e8d27815476 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Mon, 17 Jan 2011 14:54:02 -0800 Subject: ENH: core: Replace PyArray_CastTo with a call to PyArray_CopyInto Since CopyInto uses the dtype transfer mechanism to do the copying, this also fully handles casting. This also exposed a byte order issue in the dtype transfer code of converting to object arrays. The switch from position-based structure copying to name-based copying required a small change to a masked array test as well. --- numpy/ma/tests/test_core.py | 10 ++++++++-- numpy/ma/testutils.py | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'numpy/ma') diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index e3b7b99ef..c55559001 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1366,12 +1366,18 @@ class TestFillingValues(TestCase): fval = _check_fill_value(fill_val, ndtype) self.assertTrue(isinstance(fval, ndarray)) assert_equal(fval.item(), [-999, -12345678.9, asbytes("???")]) + #.....Using a flexible type w/ a different type shouldn't matter - fill_val = np.array((-999, -12345678.9, "???"), - dtype=[("A", int), ("B", float), ("C", "|S3")]) + # BEHAVIOR in 1.5 and earlier: match structured types by position + #fill_val = np.array((-999, -12345678.9, "???"), + # dtype=[("A", int), ("B", float), ("C", "|S3")]) + # BEHAVIOR in 1.6 and later: match structured types by name + fill_val = np.array(("???", -999, -12345678.9), + dtype=[("c", "|S3"), ("a", int), ("b", float), ]) fval = _check_fill_value(fill_val, ndtype) self.assertTrue(isinstance(fval, ndarray)) assert_equal(fval.item(), [-999, -12345678.9, asbytes("???")]) + #.....Using an object-array shouldn't matter either fill_value = np.array((-999, -12345678.9, "???"), dtype=object) fval = _check_fill_value(fill_val, ndtype) diff --git a/numpy/ma/testutils.py b/numpy/ma/testutils.py index 2b69cc4ad..235aac6e4 100644 --- a/numpy/ma/testutils.py +++ b/numpy/ma/testutils.py @@ -77,8 +77,7 @@ def assert_equal_records(a, b): def assert_equal(actual, desired, err_msg=''): - """Asserts that two items are equal. - """ + "Asserts that two items are equal." # Case #1: dictionary ..... if isinstance(desired, dict): if not isinstance(actual, dict): @@ -94,7 +93,10 @@ def assert_equal(actual, desired, err_msg=''): return _assert_equal_on_sequences(actual, desired, err_msg='') if not (isinstance(actual, ndarray) or isinstance(desired, ndarray)): msg = build_err_msg([actual, desired], err_msg,) - if not desired == actual: + try: + if not desired == actual: + raise AssertionError(msg) + except ValueError: raise AssertionError(msg) return # Case #4. arrays or equivalent -- cgit v1.2.1