From afa144d4a57e1da99b75327722d6605bf35a4a85 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Fri, 28 Apr 2023 14:41:00 +0200 Subject: [PATCH] BUG: Fix masked array ravel order for A (and somewhat K) Swaps the order to the correct thing and thus closes gh-23651 --- numpy/ma/core.py | 2 +- numpy/ma/tests/test_core.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/numpy/ma/core.py b/numpy/ma/core.py index acf1a04441d6..5fb16d0cba69 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -4656,7 +4656,7 @@ def ravel(self, order='C'): # TODO: We don't actually support K, so use A instead. We could # try to guess this correct by sorting strides or deprecate. if order in "kKaA": - order = "C" if self._data.flags.fnc else "F" + order = "F" if self._data.flags.fnc else "C" r = ndarray.ravel(self._data, order=order).view(type(self)) r._update_from(self) if self._mask is not nomask: diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 6c03e0ba23a1..722b3ded4fbe 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -3441,6 +3441,8 @@ def test_ravel_order(self, order, data_order): raveled = x.ravel(order) assert (raveled.filled(0) == 0).all() + # NOTE: Can be wrong if arr order is neither C nor F and `order="K"` + assert_array_equal(arr.ravel(order), x.ravel(order)._data) def test_reshape(self): # Tests reshape