Skip to content

Commit 4d1e0e3

Browse files
committed
Fix compatibility issue with *Numpy* 2.0.
1 parent 40b3081 commit 4d1e0e3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

colour_datasets/loaders/hung1995.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from __future__ import annotations
2020

21+
import csv
2122
import os
2223
import typing
2324
from dataclasses import dataclass
@@ -147,13 +148,23 @@ def load(
147148
for filename in filenames:
148149
datafile_path = os.path.join(self.record.repository, "dataset", filename)
149150

150-
self._content[filename.split(".")[0]] = np.genfromtxt(
151-
datafile_path,
152-
delimiter=",",
153-
names=True,
154-
dtype=None,
155-
encoding="utf-8",
156-
)
151+
# NOTE: Use csv module to avoid NumPy 2.x genfromtxt dtype=None errors
152+
with open(datafile_path, encoding="utf-8") as csvfile:
153+
reader = csv.reader(csvfile)
154+
headers = [h.strip().replace(" ", "_") for h in next(reader)]
155+
rows = []
156+
for row in reader:
157+
converted = []
158+
for value in row:
159+
try:
160+
converted.append(float(value))
161+
except ValueError:
162+
converted.append(value)
163+
rows.append(tuple(converted))
164+
165+
dtypes = [(name, object) for name in headers]
166+
data = np.array(rows, dtype=dtypes)
167+
self._content[filename.split(".")[0]] = data
157168

158169
hues = [
159170
"Red",

0 commit comments

Comments
 (0)