File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ def __init__(self, value):
1515 value = np .asarray (value )
1616
1717 if value .dtype != np .bool :
18- warn ('expected elements to be boolean' , stacklevel = 2 )
18+ # allow result of np.unpackbits
19+ if value .dtype != np .uint8 or np .any (value > 1 ):
20+ warn ('expected elements to be boolean' , stacklevel = 2 )
1921 value = value .astype (bool )
2022
2123 if value .ndim != 1 :
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ def test_ndarray(self):
3030 assert Bit (arr ).to_list () == [True , False , True ]
3131 assert np .array_equal (Bit (arr ).to_numpy (), arr )
3232
33+ def test_ndarray_unpackbits (self ):
34+ arr = np .unpackbits (np .array ([254 , 7 , 0 ], dtype = np .uint8 ))
35+ assert Bit (arr ).to_text () == '111111100000011100000000'
36+
3337 def test_ndarray_uint8 (self ):
3438 arr = np .array ([254 , 7 , 0 ], dtype = np .uint8 )
3539 with pytest .warns (UserWarning , match = 'expected elements to be boolean' ):
You can’t perform that action at this time.
0 commit comments