File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,11 @@ def __init__(self, value):
7
7
if isinstance (value , str ):
8
8
self ._value = self .from_text (value )._value
9
9
else :
10
- # TODO raise if dtype not bool or uint8
11
- if isinstance (value , np .ndarray ) and value .dtype == np .uint8 :
12
- value = np .unpackbits (value )
10
+ if isinstance (value , np .ndarray ):
11
+ if value .dtype == np .uint8 :
12
+ value = np .unpackbits (value ).astype (bool )
13
+ elif value .dtype != np .bool :
14
+ raise ValueError ('expected dtype to be bool or uint8' )
13
15
else :
14
16
value = np .asarray (value , dtype = bool )
15
17
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ def test_ndarray_uint8(self):
17
17
arr = np .array ([254 , 7 , 0 ], dtype = np .uint8 )
18
18
assert Bit (arr ).to_text () == '111111100000011100000000'
19
19
20
+ def test_ndarray_uint16 (self ):
21
+ arr = np .array ([254 , 7 , 0 ], dtype = np .uint16 )
22
+ with pytest .raises (ValueError ) as error :
23
+ Bit (arr )
24
+ assert str (error .value ) == 'expected dtype to be bool or uint8'
25
+
20
26
def test_ndarray_same_object (self ):
21
27
arr = np .array ([True , False , True ])
22
28
assert Bit (arr ).to_list () == [True , False , True ]
You can’t perform that action at this time.
0 commit comments