Skip to content

Commit 0af592d

Browse files
author
kx79wq
committed
[fix]: In numpy 2.3, converting np.number to a dtype no longer allowed
numpy/numpy#28254 When constructing a dtype from a class with a dtype attribute, that attribute must be a dtype-instance rather than a thing that can be parsed as a dtype instance. hist.datatype now returns float instead of np.number as datatype.
1 parent 642d89d commit 0af592d

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

histogrammar/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ def get_datatype(hist, itr=0):
533533
return []
534534
if isinstance(hist, histogrammar.Bag):
535535
if hist.dimension > 0:
536-
return [np.number] * hist.dimension
537-
return [str] if hist.range == "S" else [np.number]
536+
return [float] * hist.dimension
537+
return [str] if hist.range == "S" else [float]
538538
if isinstance(
539539
hist,
540540
(
@@ -550,7 +550,7 @@ def get_datatype(hist, itr=0):
550550
return []
551551
# else: no parent histogram.
552552
# input datatype must be a number. Let's also make an educated guess if it's a converted timestamp
553-
datatype = [np.number]
553+
datatype = [float]
554554
if isinstance(hist, histogrammar.Maximize):
555555
value = hist.max
556556
elif isinstance(hist, histogrammar.Minimize):
@@ -582,7 +582,7 @@ def get_datatype(hist, itr=0):
582582
else:
583583
# input datatype must be a number.
584584
# let's make an educated guess if it's a converted timestamp
585-
datatype = [np.number]
585+
datatype = [float]
586586
if isinstance(hist, (histogrammar.Bin, histogrammar.SparselyBin)):
587587
values = [hist.low, hist.high]
588588
elif isinstance(hist, histogrammar.CentrallyBin):

tests/test_numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ def test_datatype(self):
11111111
df, hist1, hist2, hist3 = get_test_histograms1()
11121112

11131113
assert hist1.datatype == str
1114-
np.testing.assert_array_equal(hist2.datatype, [np.number, str])
1115-
np.testing.assert_array_equal(hist3.datatype, [np.datetime64, np.number, str])
1114+
np.testing.assert_array_equal(hist2.datatype, [float, str])
1115+
np.testing.assert_array_equal(hist3.datatype, [np.datetime64, float, str])
11161116

11171117
def test_n_bins(self):
11181118
"""Test getting the number of allocated bins"""

0 commit comments

Comments
 (0)