Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -2372,12 +2372,15 @@ cdef class Array(_PandasConvertible):
)
# Note: from March 2025 onwards, it's okay to raise BufferError here.
# Still we keep the V0 version as the V1 was only added in August 2026.
legacy_tensor = GetResultValue(ExportArrayToDLPack(self.sp_array))
# Wrap the exported tensor in its capsule before warning so that a
# warning escalated to an error cannot leak the tensor.
capsule = PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
warnings.warn(
"Exporting an unversioned DLPack capsule is deprecated, "
"pass max_version=(1, 0) or higher.",
DeprecationWarning, stacklevel=2)
legacy_tensor = GetResultValue(ExportArrayToDLPack(self.sp_array))
return PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
return capsule

# Currently no major version other than legacy 0 and current 1.3
dlm_tensor = GetResultValue(
Expand Down
7 changes: 5 additions & 2 deletions python/pyarrow/tensor.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,15 @@ strides: {self.strides}"""
)
# Note: from March 2025 onwards, it's okay to raise BufferError here.
# Still we keep the V0 version as the V1 was only added in August 2026.
legacy_tensor = GetResultValue(ExportTensorToDLPack(self.sp_tensor))
# Wrap the exported tensor in its capsule before warning so that a
# warning escalated to an error cannot leak the tensor.
capsule = PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
warnings.warn(
"Exporting an unversioned DLPack capsule is deprecated, "
"pass max_version=(1, 0) or higher.",
DeprecationWarning, stacklevel=2)
legacy_tensor = GetResultValue(ExportTensorToDLPack(self.sp_tensor))
return PyCapsule_New(legacy_tensor, 'dltensor', dlpack_pycapsule_deleter)
return capsule

# Currently no major version other than legacy 0 and current 1.3
dlm_tensor = GetResultValue(
Expand Down
8 changes: 8 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,10 @@ def test_array_from_list_of_timestamps(unit):


@pytest.mark.numpy
@pytest.mark.filterwarnings(
"ignore:The 'generic' unit for NumPy timedelta is deprecated:"
"DeprecationWarning"
)
def test_array_from_timestamp_with_generic_unit():
n = np.datetime64('NaT')
x = np.datetime64('2017-01-01 01:01:01.111111111')
Expand Down Expand Up @@ -2718,6 +2722,10 @@ def test_array_from_numpy_timedelta(dtype, type):


@pytest.mark.numpy
@pytest.mark.filterwarnings(
"ignore:The 'generic' unit for NumPy timedelta is deprecated:"
"DeprecationWarning"
)
def test_array_from_numpy_timedelta_incorrect_unit():
# generic (no unit)
td = np.timedelta64(1)
Expand Down
6 changes: 3 additions & 3 deletions python/pyarrow/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2645,8 +2645,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")
Expand Down Expand Up @@ -2969,7 +2969,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) for x in timestamps])
_check_temporal_rounding(ts, values, unit)

timezones = ["Asia/Kolkata", "America/New_York", "Etc/GMT-4", "Etc/GMT+4",
Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions python/pyarrow/tests/test_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_dlpack_versioned_capsule(obj, max_version, copy):
@check_bytes_allocated
@pytest.mark.parametrize('obj', dlpack_objects())
def test_dlpack_versioned_roundtrip(obj):
expected = np.from_dlpack(DLPackForwarder(obj, max_version=None))
expected = np.from_dlpack(DLPackForwarder(obj, max_version=(1, 0)))
for copy in [None, False, True]:
result = np.from_dlpack(
DLPackForwarder(obj, max_version=(1, 0), copy=copy))
Expand Down Expand Up @@ -335,24 +335,24 @@ def test_dlpack_not_supported():
arr = pa.array([1, None, 3])
with pytest.raises(TypeError, match="Can only use DLPack "
"on arrays with no nulls."):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

arr = pa.array(
[[0, 1], [3, 4]],
type=pa.list_(pa.int32())
)
with pytest.raises(TypeError, match="DataType is not compatible with DLPack spec"):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

arr = pa.array([])
with pytest.raises(TypeError, match="DataType is not compatible with DLPack spec"):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))

# DLPack doesn't support bit-packed boolean values
arr = pa.array([True, False, True])
with pytest.raises(TypeError, match="Bit-packed boolean data type "
"not supported by DLPack."):
np.from_dlpack(arr)
np.from_dlpack(DLPackForwarder(arr, max_version=(1, 0)))


def test_dlpack_cuda_not_supported():
Expand Down
3 changes: 2 additions & 1 deletion python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def _check_pandas_roundtrip(df, expected=None, use_threads=False,
warnings.filterwarnings(
"ignore", "elementwise comparison failed", DeprecationWarning)
tm.assert_frame_equal(result, expected, check_dtype=check_dtype,
check_freq=False,
check_index_type=('equiv' if preserve_index
else False))

Expand Down Expand Up @@ -5006,7 +5007,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, "ns")]})
t = pa.Table.from_pandas(df)
t.to_pandas()

Expand Down
Loading