This is an automated email from the ASF dual-hosted git repository.
AlenkaF pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 1afe206b146 GH-51301: Fix deprecation warnings in the tests with
numpy/pandas nightly (#51404)
1afe206b146 is described below
commit 1afe206b146cb0304a1a59f3096fd076ce69da34
Author: Alenka Frim <[email protected]>
AuthorDate: Tue Oct 6 13:32:50 2026 +0200
GH-51301: Fix deprecation warnings in the tests with numpy/pandas nightly
(#51404)
### Rationale for this change
Test warnings accumulated in our CI.
### What changes are included in this PR?
The warnings are fixed or filtered if the deprecated functionality is still
being tested.
### Are these changes tested?
Yes.
### Are there any user-facing changes?
No. Fixing test warnings in our CI.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [x] Human
- [ ] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
* GitHub Issue: #51301
Lead-authored-by: AlenkaF <[email protected]>
Co-authored-by: Alenka Frim <[email protected]>
Co-authored-by: Copilot Autofix powered by AI
<[email protected]>
Co-authored-by: Rok Mihevc <[email protected]>
Co-authored-by: Joris Van den Bossche <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
---
python/pyarrow/tests/test_array.py | 13 +++++++++----
python/pyarrow/tests/test_compute.py | 6 +++---
python/pyarrow/tests/test_dataset.py | 2 +-
python/pyarrow/tests/test_pandas.py | 11 ++++++-----
4 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/python/pyarrow/tests/test_array.py
b/python/pyarrow/tests/test_array.py
index 38a131f5d95..74ff837e16e 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -36,6 +36,7 @@ except ImportError:
import pyarrow as pa
import pyarrow.tests.strategies as past
import pyarrow.compute as pc
+from pyarrow.vendored.version import Version
@pytest.mark.processes
@@ -2737,6 +2738,8 @@ def test_array_from_list_of_timestamps(unit):
@pytest.mark.numpy
def test_array_from_timestamp_with_generic_unit():
+ if Version(np.__version__) >= Version("2.5.0"):
+ pytest.skip("generic units of timedelta64 deprecated")
n = np.datetime64('NaT')
x = np.datetime64('2017-01-01 01:01:01.111111111')
y = np.datetime64('2018-11-22 12:24:48.111111111')
@@ -2778,11 +2781,13 @@ def test_array_from_numpy_timedelta(dtype, type):
@pytest.mark.numpy
def test_array_from_numpy_timedelta_incorrect_unit():
# generic (no unit)
- td = np.timedelta64(1)
+ if Version(np.__version__) < Version("2.5.0"):
+ # Generic units of timedelta64 deprecated in NumPy 2.5
+ td = np.timedelta64(1)
- for data in [[td], np.array([td])]:
- with pytest.raises(NotImplementedError):
- pa.array(data)
+ for data in [[td], np.array([td])]:
+ with pytest.raises(NotImplementedError):
+ pa.array(data)
# unsupported unit
td = np.timedelta64(1, 'M')
diff --git a/python/pyarrow/tests/test_compute.py
b/python/pyarrow/tests/test_compute.py
index a146278a8b1..d4d44e9347e 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -2656,8 +2656,8 @@ def _check_datetime_components(timestamps, timezone=None):
year = ts.dt.year.astype("int64")
month = ts.dt.month.astype("int64")
day = ts.dt.day.astype("int64")
- dayofweek = ts.dt.dayofweek.astype("int64")
- dayofyear = ts.dt.dayofyear.astype("int64")
+ dayofweek = ts.dt.day_of_week.astype("int64")
+ dayofyear = ts.dt.day_of_year.astype("int64")
quarter = ts.dt.quarter.astype("int64")
hour = ts.dt.hour.astype("int64")
minute = ts.dt.minute.astype("int64")
@@ -2980,7 +2980,7 @@ def test_round_temporal(unit):
if sys.platform == "win32":
timestamps = timestamps[:3] + timestamps[5:]
- ts = pd.Series([pd.Timestamp(x, unit="ns") for x in timestamps])
+ ts = pd.Series([pd.Timestamp(x).as_unit("ns") for x in timestamps])
_check_temporal_rounding(ts, values, unit)
timezones = ["Asia/Kolkata", "America/New_York", "Etc/GMT-4", "Etc/GMT+4",
diff --git a/python/pyarrow/tests/test_dataset.py
b/python/pyarrow/tests/test_dataset.py
index 0a94c0bd987..9ddfdfdc9c4 100644
--- a/python/pyarrow/tests/test_dataset.py
+++ b/python/pyarrow/tests/test_dataset.py
@@ -240,7 +240,7 @@ def multisourcefs(request):
# create one with schema partitioning by weekday and color
mockfs.create_dir('schema')
- for part, chunk in df_b.groupby([df_b.date.dt.dayofweek, df_b.color]):
+ for part, chunk in df_b.groupby([df_b.date.dt.day_of_week, df_b.color]):
folder = f'schema/{part[0]}/{part[1]}'
path = f'{folder}/chunk.parquet'
mockfs.create_dir(folder)
diff --git a/python/pyarrow/tests/test_pandas.py
b/python/pyarrow/tests/test_pandas.py
index 6fc9925eb01..9421b345269 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -99,8 +99,8 @@ def _alltypes_example(size=100):
def _check_pandas_roundtrip(df, expected=None, use_threads=False,
expected_schema=None,
- check_dtype=True, schema=None,
- preserve_index=False,
+ check_dtype=True, check_freq=True,
+ schema=None, preserve_index=False,
as_batch=False):
klass = pa.RecordBatch if as_batch else pa.Table
table = klass.from_pandas(df, schema=schema,
@@ -125,7 +125,8 @@ def _check_pandas_roundtrip(df, expected=None,
use_threads=False,
"ignore", "elementwise comparison failed", DeprecationWarning)
tm.assert_frame_equal(result, expected, check_dtype=check_dtype,
check_index_type=('equiv' if preserve_index
- else False))
+ else False),
+ check_freq=check_freq)
def _check_series_roundtrip(s, type_=None, expected_pa_type=None):
@@ -223,7 +224,7 @@ class TestConvertMetadata:
np.random.randn(5, 3),
columns=pd.date_range("2021-01-01", periods=3, freq="50D", tz=tz)
)
- _check_pandas_roundtrip(df, preserve_index=True)
+ _check_pandas_roundtrip(df, preserve_index=True, check_freq=False)
def test_column_index_names_with_decimal(self):
# GH-41503: Test valid roundtrip with decimal value in column index
@@ -5016,7 +5017,7 @@ def test_does_not_mutate_timedelta_dtype():
assert np.dtype(np.timedelta64) == expected
- df = pd.DataFrame({"a": [np.timedelta64()]})
+ df = pd.DataFrame({"a": [np.timedelta64(0, "s")]})
t = pa.Table.from_pandas(df)
t.to_pandas()