summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-03-18 11:28:18 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2021-03-18 11:28:18 -0500
commitb5de1ceb1f1707d0539446b3d8883f3f8f80cb69 (patch)
tree0eef93998e2c4244d7526b63e10314c86407f6ae
parentb32198f058ebb5b81f9818fbaf2ad832bea16dba (diff)
downloadnumpy-b5de1ceb1f1707d0539446b3d8883f3f8f80cb69.tar.gz
MAINT: Add comment to unused func, silence linter and avoid non-contig error
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.c.src5
-rw-r--r--numpy/core/tests/test_casting_unittests.py10
-rw-r--r--numpy/core/tests/test_datetime.py15
3 files changed, 18 insertions, 12 deletions
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
index 8a6948fa4..631042dae 100644
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -285,6 +285,11 @@ _strided_to_strided(
return 0;
}
+/*
+ * NOTE: This function is currently unused. It would currently be used for
+ * builtin dtypes that have an elsize other than 2, 4, 8, or 16 bytes.
+ * Since unicode and complex swap differently, no such dtype exists.
+ */
static int
_swap_strided_to_strided(
PyArrayMethod_Context *context, char *const *args,
diff --git a/numpy/core/tests/test_casting_unittests.py b/numpy/core/tests/test_casting_unittests.py
index 45d58a23a..c8fcd4b42 100644
--- a/numpy/core/tests/test_casting_unittests.py
+++ b/numpy/core/tests/test_casting_unittests.py
@@ -626,20 +626,20 @@ class TestCasting:
# that tests unicode bytedwaps including for unaligned array data.
dtype1 = np.dtype(f"{order1}U30")
dtype2 = np.dtype(f"{order2}U30")
- data1 = np.empty(30 * 4 + 1, dtype=np.uint8)[None, 1:].view(dtype1)
- data2 = np.empty(30 * 4 + 1, dtype=np.uint8)[None, 1:].view(dtype2)
+ data1 = np.empty(30 * 4 + 1, dtype=np.uint8)[1:].view(dtype1)
+ data2 = np.empty(30 * 4 + 1, dtype=np.uint8)[1:].view(dtype2)
if dtype1.alignment != 1:
# alignment should always be >1, but skip the check if not
assert not data1.flags.aligned
assert not data2.flags.aligned
element = "this is a ünicode string‽"
- data1[0] = element
+ data1[()] = element
# Test both `data1` and `data1.copy()` (which should be aligned)
for data in [data1, data1.copy()]:
data2[...] = data1
- assert data2[0] == element
- assert data2.copy()[0] == element
+ assert data2[()] == element
+ assert data2.copy()[()] == element
def test_void_to_string_special_case(self):
# Cover a small special case in void to string casting that could
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index d2c04a506..b4146eadf 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -705,12 +705,12 @@ class TestDateTime:
# Test that every byte-swapping combination also returns the same
# results (previous tests check that this comparison works fine).
- res1 = times.astype(dtype1.newbyteorder()).astype(dtype2)
- assert_array_equal(res1, expected)
- res2 = times.astype(dtype2.newbyteorder())
- assert_array_equal(res2, expected)
- res3 = times.astype(dtype1.newbyteorder()).astype(dtype2.newbyteorder())
- assert_array_equal(res3, expected)
+ res = times.astype(dtype1.newbyteorder()).astype(dtype2)
+ assert_array_equal(res, expected)
+ res = times.astype(dtype2.newbyteorder())
+ assert_array_equal(res, expected)
+ res = times.astype(dtype1.newbyteorder()).astype(dtype2.newbyteorder())
+ assert_array_equal(res, expected)
@pytest.mark.parametrize("time_dtype", ["m8[D]", "M8[Y]"])
@pytest.mark.parametrize("str_dtype", ["U", "S"])
@@ -732,7 +732,8 @@ class TestDateTime:
assert_array_equal(res, to_strings)
# Check that conversion from string to times works if src is swapped:
- from_strings_swapped = from_strings.astype(from_strings.dtype.newbyteorder())
+ from_strings_swapped = from_strings.astype(
+ from_strings.dtype.newbyteorder())
res = from_strings_swapped.astype(time_dtype)
assert_array_equal(res, times)
# And if both are swapped: