From 8ca7f15684a1cd475dd2a9942ab243cb632ccf3b Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 7 Nov 2024 10:13:29 -0600 Subject: [PATCH] fix: adjust for Pandas changing its API again (#1322) --- src/uproot/interpretation/library.py | 7 ++++++- tests/test_1321_pandas_changed_api_again.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/test_1321_pandas_changed_api_again.py diff --git a/src/uproot/interpretation/library.py b/src/uproot/interpretation/library.py index fc6947fd0..c79c2f2c3 100644 --- a/src/uproot/interpretation/library.py +++ b/src/uproot/interpretation/library.py @@ -919,7 +919,12 @@ def global_index(self, arrays, global_offset): ) else: - index = arrays.index.arrays + # arrays.index.values before Pandas 0.24 and again now; + # arrays.index.arrays from Pandas 0.24 through some time ago. + if hasattr(arrays.index, "values"): + index = arrays.index.values + else: + index = arrays.index.arrays numpy.add(index, global_offset, out=index) return arrays diff --git a/tests/test_1321_pandas_changed_api_again.py b/tests/test_1321_pandas_changed_api_again.py new file mode 100644 index 000000000..5dcf46168 --- /dev/null +++ b/tests/test_1321_pandas_changed_api_again.py @@ -0,0 +1,20 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE + +import pytest +import skhep_testdata +import uproot + +pytest.importorskip("pandas") + + +def test(): + assert ( + len( + uproot.concatenate( + skhep_testdata.data_path("uproot-Zmumu.root"), + library="pd", + cut="Run > 148029", + ) + ) + == 1580 + )