Skip to content

Commit 0385222

Browse files
authored
Fixed booleans from being converted to integers in make_array (#629)
* fix booleans for make_array * update fix to bools * add tests * added an additional line in docstring
1 parent d3b75b3 commit 0385222

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

datascience/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ def make_array(*elements):
3636
>>> make_array("foo", "bar")
3737
array(['foo', 'bar'],
3838
dtype='<U3')
39+
>>> make_array(True, False)
40+
array([ True, False], dtype=bool)
3941
>>> make_array()
4042
array([], dtype=float64)
4143
"""
42-
if elements and all(isinstance(item, (int, np.integer)) for item in elements):
44+
if elements and all(isinstance(item, (int, np.integer)) and not isinstance(item, bool) for item in elements):
4345
# Specifically added for Windows machines where the default
4446
# integer is int32 - see GH issue #339.
47+
# and ensures item is not bool, see issue #622.
4548
return np.array(elements, dtype="int64")
4649

4750
# Manually cast `elements` as an object due to this: https://github.com/data-8/datascience/issues/458

tests/test_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def test_make_array():
2020
assert test3.dtype == "<U3"
2121
test4 = ds.make_array(list(range(10)))
2222
assert test4.dtype == "object"
23+
test5 = ds.make_array(True, False)
24+
assert test5.dtype == "bool"
2325

2426

2527
def test_percentile():
@@ -121,4 +123,4 @@ def __getitem__(self, index):
121123
def __len__(self):
122124
pass
123125
is_sequence = IsSequence()
124-
assert ds.is_non_string_iterable(is_sequence) == True
126+
assert ds.is_non_string_iterable(is_sequence) == True

0 commit comments

Comments
 (0)