Skip to content

Commit 7aa82fd

Browse files
DCHartlencodie3611
andauthored
Migrate to Numpy 2.2+ and Python 3.11+ (#87)
* refact: Move minimum python version to 3.11 Python 3.11 is the minimum version supported by NumPy 2.3. Additionally, removed .python-version, which pins the development version of Python to 3.9. * refact: Updates Numpy to >2.2 From personal experience, there was a not-insignificant depreciation between 2.1 and 2.2 that caught me out before related to indexing arrays. Skipping to 2.2 avoids this deprecation. * refact: Disable UP007 Linting Rule UP007 is related to a change in typing detailed in PEP604. Typing Unions can now be written as `X | Y` instead of `Union[int, str]`. There is no deprecation for this feature, and a significant amount of legacy code needs to be updated. * refact: Update `zip()` calls to include `strict=False` per B905 Adds `strict=False` to all `zip()` calls to fix Ruff linter Rule B905 (https://docs.astral.sh/ruff/rules/zip-without-explicit-strict/). `strict=False` maintains current behaviour while fixing the linter error. There is no impact on unit tests with this change. * Bump test version --------- Co-authored-by: Codie <5020407+codie3611@users.noreply.github.com>
1 parent 25effb6 commit 7aa82fd

File tree

9 files changed

+660
-843
lines changed

9 files changed

+660
-843
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
strategy:
15-
# If either the tests for 3.9 or 3.12 fail, all workflows
15+
# If either the tests for 3.11 or 3.12 fail, all workflows
1616
# are terminated to save computing resources.
1717
fail-fast: true
1818
# To safe runtime least and latest version supported are
1919
# chosen. For more info see the pyproject.toml
2020
matrix:
21-
python-version: ["3.9", "3.12"]
21+
python-version: ["3.11", "3.12"]
2222

2323
steps:
2424
- uses: actions/checkout@v3

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@ classifiers = [
1313
"Operating System :: Microsoft :: Windows",
1414
"Operating System :: POSIX :: Linux",
1515
"Programming Language :: Python :: 3",
16-
"Programming Language :: Python :: 3.9",
17-
"Programming Language :: Python :: 3.10",
1816
"Programming Language :: Python :: 3.11",
1917
"Programming Language :: Python :: 3.12",
2018
]
2119

22-
requires-python = ">=3.9"
20+
requires-python = ">=3.11"
2321
dependencies = [
2422
"h5py==3.*",
2523
"scipy==1.*",
26-
"numpy==1.*",
24+
"numpy>2.2",
2725
"plotly==5.*",
2826
"psutil==5.*",
2927
"rich==13.*",
3028
"pandas==2.*",
31-
"scikit_learn==1.*"
29+
"scikit_learn==1.*",
3230
]
3331

3432
[tool.setuptools]
@@ -89,6 +87,7 @@ select = [
8987
"YTT", # flake8-2020 (Detects outdated Python 2/3 compatibility issues)
9088
"FLY", # flynt (Converts old-style string formatting to f-strings)
9189
"PIE", # flake8-pie
90+
"NPY201", # numpy2-deprecations
9291
# "PL", # pylint
9392
# "RUF", # Ruff-specific rules (Additional optimizations and best practices)
9493
]
@@ -99,6 +98,7 @@ ignore = [
9998
"S311", # [suspicious-non-cryptographic-random-usage](https://docs.astral.sh/ruff/rules/suspicious-non-cryptographic-random-usage/)
10099
"S404", # [suspicious-subprocess-import](https://docs.astral.sh/ruff/rules/suspicious-subprocess-import/)
101100
"S603", # [subprocess-without-shell-equals-true](https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/)
101+
"UP007", # [non-pep604-annotation-union](https://docs.astral.sh/ruff/rules/non-pep604-annotation-union/#non-pep604-annotation-union-up007)
102102
]
103103

104104
[tool.ruff.lint.per-file-ignores]

src/lasso/dimred/graph_laplacian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _laplacian_gauss_idw(
9797
for i, (j, d, e, k) in enumerate(
9898
zip(
9999
*tree.query_radius(points, return_distance=True, r=search_radius),
100-
*tree.query(points, return_distance=True, k=1 + min_neighbors),
100+
*tree.query(points, return_distance=True, k=1 + min_neighbors), strict=False,
101101
)
102102
):
103103
# Always search for k neighbors, this prevents strongly connected local areas

src/lasso/dimred/hashing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _join_hash_comparison_thread_files(
211211
thread_weights = thread_file["weights"]
212212

213213
for (i_row, i_col), values, matches in zip(
214-
matrix_indexes, matrix_similarities, matrix_matches
214+
matrix_indexes, matrix_similarities, matrix_matches, strict=False
215215
):
216216
smatrix[i_row, i_col] = values
217217
ds_matches[i_row, i_col] = matches

src/lasso/dyna/binout.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def as_df(self, *args) -> pd.DataFrame:
200200
if args[0] == "rcforc":
201201
ids = [
202202
(str(i) + "m") if j else (str(i) + "s")
203-
for i, j in zip(self.read("rcforc", "ids"), self.read("rcforc", "side"))
203+
for i, j in zip(
204+
self.read("rcforc", "ids"), self.read("rcforc", "side"), strict=False
205+
)
204206
]
205207
else:
206208
ids = self.read(*args[:-1], "ids")

src/lasso/dyna/d3plot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7162,7 +7162,9 @@ def _write_geom_rigid_road_surface(
71627162
rigid_road_segment_road_id = self.arrays[ArrayType.rigid_road_segment_road_id]
71637163
rigid_road_segment_node_ids = self.arrays[ArrayType.rigid_road_segment_node_ids]
71647164

7165-
for segment_id, node_ids in zip(rigid_road_segment_road_id, rigid_road_segment_node_ids):
7165+
for segment_id, node_ids in zip(
7166+
rigid_road_segment_road_id, rigid_road_segment_node_ids, strict=False
7167+
):
71667168
n_bytes_written += fp.write(settings.pack(segment_id))
71677169
n_bytes_written += fp.write(settings.pack(len(node_ids)))
71687170
n_bytes_written += fp.write(settings.pack(node_ids, dtype_hint=np.integer))
@@ -7347,7 +7349,7 @@ def _write_header_part_contact_interface_titles(
73477349
title_wordsize = 4
73487350
max_len = 18 * title_wordsize
73497351
fmt_name = "{0:" + str(max_len) + "}"
7350-
for pid, title in zip(part_titles_ids, part_titles):
7352+
for pid, title in zip(part_titles_ids, part_titles, strict=False):
73517353
title = title.decode("utf-8")
73527354
n_bytes_written += fp.write(settings.pack(pid))
73537355

@@ -7387,7 +7389,7 @@ def _write_header_part_contact_interface_titles(
73877389

73887390
max_len = 18 * self.header.wordsize
73897391
fmt_name = "{0:" + str(max_len) + "}"
7390-
for pid, title in zip(titles_ids, titles):
7392+
for pid, title in zip(titles_ids, titles, strict=False):
73917393
n_bytes_written += fp.write(settings.pack(pid))
73927394

73937395
formatted_title = fmt_name.format(title[:max_len])

test/unit_tests/dyna/test_d3plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def test_write(self):
334334

335335
with tempfile.TemporaryDirectory() as dirpath:
336336
for d3plot_kwargs in d3plot_kwargs_list:
337-
for d3plot_filepath, _ in zip(filepaths, d3plot_kwargs_list):
337+
for d3plot_filepath, _ in zip(filepaths, d3plot_kwargs_list, strict=False):
338338
print(d3plot_filepath)
339339

340340
# read d3plot

0 commit comments

Comments
 (0)