From 476b9d8324bf71e3e46ab5a31176943b7445a0c7 Mon Sep 17 00:00:00 2001 From: Tim Xie Date: Mon, 10 Mar 2025 16:14:48 -0700 Subject: [PATCH 1/4] fix booleans for make_array --- datascience/util.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/datascience/util.py b/datascience/util.py index 67aca12b9..d27cb6ba3 100644 --- a/datascience/util.py +++ b/datascience/util.py @@ -39,6 +39,11 @@ def make_array(*elements): >>> make_array() array([], dtype=float64) """ + if elements and all(isinstance(item, bool) for item in elements): + # Explicit check for bool, so it is not converted to int + # as Python bools will have isinstance(.., int) as True + return np.array(elements, dtype=bool) + if elements and all(isinstance(item, (int, np.integer)) for item in elements): # Specifically added for Windows machines where the default # integer is int32 - see GH issue #339. From b891937aa311b2b1059b56c633e999f3d25e0fc7 Mon Sep 17 00:00:00 2001 From: Tim Xie Date: Mon, 10 Mar 2025 22:44:18 -0700 Subject: [PATCH 2/4] update fix to bools --- datascience/util.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/datascience/util.py b/datascience/util.py index d27cb6ba3..12ccc2010 100644 --- a/datascience/util.py +++ b/datascience/util.py @@ -39,14 +39,10 @@ def make_array(*elements): >>> make_array() array([], dtype=float64) """ - if elements and all(isinstance(item, bool) for item in elements): - # Explicit check for bool, so it is not converted to int - # as Python bools will have isinstance(.., int) as True - return np.array(elements, dtype=bool) - - if elements and all(isinstance(item, (int, np.integer)) for item in elements): + if elements and all(isinstance(item, (int, np.integer)) and not isinstance(item, bool) for item in elements): # Specifically added for Windows machines where the default # integer is int32 - see GH issue #339. + # and ensures item is not bool, see issue #622. return np.array(elements, dtype="int64") # Manually cast `elements` as an object due to this: https://github.com/data-8/datascience/issues/458 From 35d35dddf9c16caba26ac9d474f229573f05839d Mon Sep 17 00:00:00 2001 From: Tim Xie Date: Mon, 10 Mar 2025 22:49:40 -0700 Subject: [PATCH 3/4] add tests --- tests/test_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_util.py b/tests/test_util.py index 95a68e3a8..dabde1e19 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -20,6 +20,8 @@ def test_make_array(): assert test3.dtype == " Date: Sat, 24 May 2025 17:37:00 -0700 Subject: [PATCH 4/4] added an additional line in docstring --- datascience/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datascience/util.py b/datascience/util.py index 12ccc2010..31abf864b 100644 --- a/datascience/util.py +++ b/datascience/util.py @@ -36,6 +36,8 @@ def make_array(*elements): >>> make_array("foo", "bar") array(['foo', 'bar'], dtype='>> make_array(True, False) + array([ True, False], dtype=bool) >>> make_array() array([], dtype=float64) """