Skip to content

Commit

Permalink
fix: update for NumPy 2.0 (#1195)
Browse files Browse the repository at this point in the history
* fix: update for NumPy 2.0

* add a workflow for NumPy 2.0

* greater or equal to
  • Loading branch information
jpivarski committed Apr 9, 2024
1 parent c3c39c0 commit b9a2a02
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 21 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,27 @@ jobs:
- name: Run pytest
run: |
python -m pytest -vv tests --reruns 10 --reruns-delay 30 --only-rerun "(?i)http|ssl|timeout|expired|connection|socket"
numpy2-build:
strategy:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-latest]
python-version: ['3.11']

runs-on: ${{ matrix.platform }}
timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Pip install the package
run: python -m pip install 'numpy>=2.0.0b1' .[test]

- name: Run pytest
run: |
python -m pytest -vv tests --reruns 10 --reruns-delay 30 --only-rerun "(?i)http|ssl|timeout|expired|connection|socket"
4 changes: 3 additions & 1 deletion src/uproot/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def ensure_numpy(array, types=(numpy.bool_, numpy.integer, numpy.floating)):

awkward = uproot.extras.awkward()
with warnings.catch_warnings():
warnings.simplefilter("error", numpy.VisibleDeprecationWarning)
warnings.simplefilter(
"error", getattr(numpy, "exceptions", numpy).VisibleDeprecationWarning
)
if isinstance(array, awkward.contents.Content):
out = awkward.to_numpy(array)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/uproot/interpretation/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def final_array(

start = stop

output = output.newbyteorder("=")
output = output.view(output.dtype.newbyteorder("="))
self.hook_before_library_finalize(
basket_arrays=basket_arrays,
entry_start=entry_start,
Expand Down
2 changes: 1 addition & 1 deletion src/uproot/source/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def bytestring(
length_data = chunk.get(start, stop, self, context)
length = numpy.frombuffer(length_data, dtype=self._u1).view(self._i4)[0]
start = stop
stop = start + length
stop = start + int(length)
if move:
self._index = stop
return uproot._util.tobytes(chunk.get(start, stop, self, context))
Expand Down
2 changes: 1 addition & 1 deletion src/uproot/streamers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ def read_members(self, chunk, cursor, context, file):
uproot.const.kULong,
uproot.const.kLong,
):
self._bases[0]._members["fSize"] = numpy.dtype(numpy.compat.long).itemsize
self._bases[0]._members["fSize"] = numpy.dtype(numpy.int64).itemsize

elif self._bases[0]._members["fType"] in (
uproot.const.kULong64,
Expand Down
17 changes: 9 additions & 8 deletions tests/test_0692_fsspec_reading.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/main/LICENSE

import pytest
import uproot
import uproot.source.fsspec
import uproot.source.file
import uproot.source.xrootd
import uproot.source.s3

from typing import BinaryIO
import skhep_testdata
import queue
Expand All @@ -15,6 +8,14 @@
import os
import sys

import pytest

import uproot
import uproot.source.fsspec
import uproot.source.file
import uproot.source.xrootd
import uproot.source.s3

is_windows = sys.platform.startswith("win")


Expand Down Expand Up @@ -243,7 +244,7 @@ def test_fsspec_chunks(http_server):
chunk = notifications.get()
expected.pop((chunk.start, chunk.stop))

chunk_data_sum = {sum(chunk.raw_data) for chunk in chunks}
chunk_data_sum = {sum(map(int, chunk.raw_data)) for chunk in chunks}
assert chunk_data_sum == {3967, 413, 10985}, "Chunk data does not match"


Expand Down
19 changes: 13 additions & 6 deletions tests/test_0692_fsspec_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ def test_fsspec_writing_local(tmp_path, scheme):
"slash_prefix",
[""] if is_windows else ["", "/"],
)
def test_fsspec_writing_local_uri(tmp_path, scheme, slash_prefix, filename):
uri = scheme + slash_prefix + os.path.join(tmp_path, "some", "path", filename)
with uproot.create(uri) as f:
f["tree"] = {"x": np.array([1, 2, 3])}
with uproot.open(uri) as f:
assert f["tree"]["x"].array().tolist() == [1, 2, 3]
def test_fsspec_writing_local_uri(tmp_path, scheme, slash_prefix, filename, request):
os.chdir(tmp_path)

try:
uri = scheme + slash_prefix + os.path.join(tmp_path, "some", "path", filename)

with uproot.create(uri) as f:
f["tree"] = {"x": np.array([1, 2, 3])}
with uproot.open(uri) as f:
assert f["tree"]["x"].array().tolist() == [1, 2, 3]

finally:
os.chdir(request.config.invocation_params.dir)


@pytest.mark.parametrize(
Expand Down
5 changes: 4 additions & 1 deletion tests/test_1070_pandas_dataframe_building_performance_fix.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import pytest
import uproot
import skhep_testdata

import uproot

pytest.importorskip("pandas")


def test_pandas_performance_many_branches(tmp_path):
for array in uproot.iterate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import pytest
import uproot
import skhep_testdata

import uproot

pytest.importorskip("pandas")


def test_decompression_executor_for_dask():

Expand Down
5 changes: 4 additions & 1 deletion tests/test_1189_dask_failing_on_duplicate_keys.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import pytest
import uproot
import skhep_testdata

import uproot

pytest.importorskip("pandas")


def test_dask_duplicated_keys():

Expand Down

0 comments on commit b9a2a02

Please sign in to comment.