Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67a8701

Browse files
committed
Fix transpose of BoolTypeArray, NativeEndiannessArray
Closes#10536
1 parent699d895 commit67a8701

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

‎doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Bug fixes
2828
- Fix Pydap Datatree backend testing. Testing now compares elements of (unordered) two sets (before, lists) (:pull:`10525`).
2929
By `Miguel Jimenez-Urias<https://github.com/Mikejmnez>`_.
3030

31+
- Fix transpose of boolean arrays read from disk. (:issue:`10536`)
32+
By `Deepak Cherian<https://github.com/dcherian>`_.
33+
3134

3235
Documentation
3336
~~~~~~~~~~~~~

‎xarray/coding/variables.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def __getitem__(self, key) -> Self:
7070
defget_duck_array(self):
7171
returnduck_array_ops.astype(self.array.get_duck_array(),dtype=self.dtype)
7272

73+
deftranspose(self,order):
74+
returntype(self)(self.array.transpose(order))
75+
7376

7477
classBoolTypeArray(indexing.ExplicitlyIndexedNDArrayMixin):
7578
"""Decode arrays on the fly from integer to boolean datatype
@@ -111,6 +114,9 @@ def __getitem__(self, key) -> Self:
111114
defget_duck_array(self):
112115
returnduck_array_ops.astype(self.array.get_duck_array(),dtype=self.dtype)
113116

117+
deftranspose(self,order):
118+
returntype(self)(self.array.transpose(order))
119+
114120

115121
def_apply_mask(
116122
data:np.ndarray,

‎xarray/tests/test_backends.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,15 @@ def create_encoded_unsigned_false_masked_scaled_data(dtype: np.dtype) -> Dataset
308308

309309
defcreate_boolean_data()->Dataset:
310310
attributes= {"units":"-"}
311-
returnDataset({"x": ("t", [True,False,False,True],attributes)})
311+
returnDataset(
312+
{
313+
"x": (
314+
("t","x"),
315+
[[False,True,False,True], [True,False,False,True]],
316+
attributes,
317+
)
318+
}
319+
)
312320

313321

314322
classTestCommon:
@@ -726,6 +734,9 @@ def test_roundtrip_boolean_dtype(self) -> None:
726734
withself.roundtrip(actual)asactual2:
727735
assert_identical(original,actual2)
728736
assertactual2["x"].dtype=="bool"
737+
withself.roundtrip(actual)asactual3:
738+
# GH10536
739+
assert_identical(original.transpose(),actual3.transpose())
729740

730741
deftest_orthogonal_indexing(self)->None:
731742
in_memory=create_test_data()

‎xarray/tests/test_conventions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def test_booltype_array(self) -> None:
3737
assertbx.dtype==bool
3838
assert_array_equal(bx,np.array([True,False,True,True,False],dtype=bool))
3939

40+
x=np.array([[1,0,1], [0,1,0]],dtype="i1")
41+
bx=coding.variables.BoolTypeArray(x)
42+
assert_array_equal(bx.transpose((1,0)),x.transpose((1,0)))
43+
4044

4145
classTestNativeEndiannessArray:
4246
deftest(self)->None:
@@ -47,6 +51,11 @@ def test(self) -> None:
4751
asserta.dtype==expected[:].dtype
4852
assert_array_equal(a,expected)
4953

54+
x=np.arange(6,dtype=">i8").reshape((2,3))
55+
a=coding.variables.NativeEndiannessArray(x)
56+
expected=np.arange(6,dtype="int64").reshape((2,3))
57+
assert_array_equal(a.transpose((1,0)),expected.transpose((1,0)))
58+
5059

5160
deftest_decode_cf_with_conflicting_fill_missing_value()->None:
5261
expected=Variable(["t"], [np.nan,np.nan,2], {"units":"foobar"})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp