This is an automated email from the ASF dual-hosted git repository.
pitrou 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 4a6ebc06dc2 GH-49153: [Python] Remove APIs deprecated before 15.0.0
(#53543)
4a6ebc06dc2 is described below
commit 4a6ebc06dc2bb967263fdf83449ac104e54cbaba
Author: Rok Mihevc <[email protected]>
AuthorDate: Mon Oct 26 20:04:24 2026 +0100
GH-49153: [Python] Remove APIs deprecated before 15.0.0 (#53543)
### Rationale for this change
We have many deprecated APIs in Python we should slowly remove.
### What changes are included in this PR?
Several deprecation messages are acted on.
### Are these changes tested?
By the existing test suite.
### Are there any user-facing changes?
Yes, some deprecated user-facing APIs are.removed.
### 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:**
- [ ] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [x] AI
- [ ] Not reviewed
* GitHub Issue: #49153
Authored-by: Rok Mihevc <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
docs/source/python/api/compute.rst | 1 -
python/pyarrow/_compute.pyx | 22 ---------------
python/pyarrow/_flight.pyx | 39 +--------------------------
python/pyarrow/array.pxi | 42 +++--------------------------
python/pyarrow/compute.py | 1 -
python/pyarrow/orc.py | 9 -------
python/pyarrow/parquet/core.py | 2 +-
python/pyarrow/table.pxi | 43 +-----------------------------
python/pyarrow/tests/parquet/test_basic.py | 14 ++++++++++
python/pyarrow/tests/test_array.py | 6 -----
python/pyarrow/tests/test_compute.py | 10 +------
python/pyarrow/tests/test_orc.py | 37 +++----------------------
python/pyarrow/tests/test_pandas.py | 7 +++++
python/pyarrow/tests/test_schema.py | 8 ++----
python/pyarrow/tests/test_table.py | 33 ++++++++---------------
python/pyarrow/types.pxi | 42 -----------------------------
16 files changed, 44 insertions(+), 272 deletions(-)
diff --git a/docs/source/python/api/compute.rst
b/docs/source/python/api/compute.rst
index 2c4da3abd18..ab9ef655b79 100644
--- a/docs/source/python/api/compute.rst
+++ b/docs/source/python/api/compute.rst
@@ -603,7 +603,6 @@ Compute Options
CastOptions
CountOptions
CumulativeOptions
- CumulativeSumOptions
DayOfWeekOptions
DictionaryEncodeOptions
ElementWiseAggregateOptions
diff --git a/python/pyarrow/_compute.pyx b/python/pyarrow/_compute.pyx
index 1c0c779f603..8211c74ca39 100644
--- a/python/pyarrow/_compute.pyx
+++ b/python/pyarrow/_compute.pyx
@@ -29,7 +29,6 @@ from pyarrow.lib cimport *
from pyarrow.includes.common cimport *
from pyarrow.includes.libarrow cimport *
import pyarrow.lib as lib
-from pyarrow.util import _DEPR_MSG
from libcpp cimport bool as c_bool
import inspect
@@ -2173,27 +2172,6 @@ class CumulativeOptions(_CumulativeOptions):
self._set_options(start, skip_nulls)
-class CumulativeSumOptions(_CumulativeOptions):
- """
- Options for `cumulative_sum` function.
-
- Parameters
- ----------
- start : Scalar, default None
- Starting value for sum computation
- skip_nulls : bool, default False
- When false, the first encountered null is propagated.
- """
-
- def __init__(self, start=None, *, skip_nulls=False):
- warnings.warn(
- _DEPR_MSG.format("CumulativeSumOptions", "14.0",
"CumulativeOptions"),
- FutureWarning,
- stacklevel=2
- )
- self._set_options(start, skip_nulls)
-
-
cdef class _PairwiseOptions(FunctionOptions):
def _set_options(self, period):
self.wrapped.reset(new CPairwiseOptions(period))
diff --git a/python/pyarrow/_flight.pyx b/python/pyarrow/_flight.pyx
index f8118fbf61c..2ab0ab618ae 100644
--- a/python/pyarrow/_flight.pyx
+++ b/python/pyarrow/_flight.pyx
@@ -21,7 +21,6 @@ import collections
import enum
import re
import time
-import warnings
import weakref
from cython.operator cimport dereference as deref
@@ -1231,7 +1230,7 @@ cdef class MetadataRecordBatchWriter(_CRecordBatchWriter):
check_flight_status(
self._writer().WriteRecordBatch(deref(batch.batch),
custom_metadata))
- def write_table(self, Table table, max_chunksize=None, **kwargs):
+ def write_table(self, Table table, max_chunksize=None):
"""
Write Table to stream in (contiguous) RecordBatch objects.
@@ -1246,13 +1245,6 @@ cdef class
MetadataRecordBatchWriter(_CRecordBatchWriter):
# max_chunksize must be > 0 to have any impact
int64_t c_max_chunksize = -1
- if 'chunksize' in kwargs:
- max_chunksize = kwargs['chunksize']
- msg = ('The parameter chunksize is deprecated for the write_table '
- 'methods as of 0.15, please use parameter '
- 'max_chunksize instead')
- warnings.warn(msg, FutureWarning)
-
if max_chunksize is not None:
c_max_chunksize = max_chunksize
@@ -1523,25 +1515,6 @@ cdef class FlightClient(_Weakrefable):
else:
break
- @classmethod
- def connect(cls, location, tls_root_certs=None, cert_chain=None,
- private_key=None, override_hostname=None,
- disable_server_verification=None):
- """Connect to a Flight server.
-
- .. deprecated:: 0.15.0
- Use the ``FlightClient`` constructor or ``pyarrow.flight.connect``
function instead.
- """
- warnings.warn("The 'FlightClient.connect' method is deprecated, use "
- "FlightClient constructor or pyarrow.flight.connect "
- "function instead")
- return FlightClient(
- location, tls_root_certs=tls_root_certs,
- cert_chain=cert_chain, private_key=private_key,
- override_hostname=override_hostname,
- disable_server_verification=disable_server_verification
- )
-
def authenticate(self, auth_handler, options: FlightCallOptions = None):
"""Authenticate to the server.
@@ -3205,16 +3178,6 @@ cdef class FlightServerBase(_Weakrefable):
with nogil:
check_flight_status(self.server.get().ServeWithSignals())
- def run(self):
- """Block until the server shuts down.
-
- .. deprecated:: 0.15.0
- Use the ``FlightServer.serve`` method instead
- """
- warnings.warn("The 'FlightServer.run' method is deprecated, use "
- "FlightServer.serve method instead")
- self.serve()
-
def shutdown(self):
"""Shut down the server, blocking until current requests finish.
diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi
index bf9a6d67228..afe7a18c528 100644
--- a/python/pyarrow/array.pxi
+++ b/python/pyarrow/array.pxi
@@ -377,27 +377,9 @@ def array(object obj, type=None, mask=None, size=None,
from_pandas=None,
indices = _codes_to_indices(
values.codes, mask, index_type, memory_pool)
- try:
- dictionary = array(
- values.categories, type=value_type,
- from_pandas=True, memory_pool=memory_pool)
- except TypeError:
- # TODO when removing the deprecation warning, this whole
- # try/except can be removed (to bubble the TypeError of
- # the first array(..) call)
- if value_type is not None:
- warnings.warn(
- "The dtype of the 'categories' of the passed "
- f"categorical values ({values.categories.dtype}) does
not match the "
- f"specified type ({value_type}). For now ignoring the
specified "
- "type, but in the future this mismatch will raise a "
- "TypeError",
- FutureWarning, stacklevel=2)
- dictionary = array(
- values.categories, from_pandas=True,
- memory_pool=memory_pool)
- else:
- raise
+ dictionary = array(
+ values.categories, type=value_type,
+ from_pandas=True, memory_pool=memory_pool)
return DictionaryArray.from_arrays(
indices, dictionary, ordered=values.ordered, safe=safe)
@@ -4041,24 +4023,6 @@ cdef class UnionArray(Array):
Concrete class for Arrow arrays of a Union data type.
"""
- def child(self, int pos):
- """
- DEPRECATED, use field() instead.
-
- Parameters
- ----------
- pos : int
- The physical index of the union child field (not its type code).
-
- Returns
- -------
- field : pyarrow.Field
- The given child field.
- """
- import warnings
- warnings.warn("child is deprecated, use field", FutureWarning)
- return self.field(pos)
-
def field(self, int pos):
"""
Return the given child field as an individual array.
diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py
index d34eccdedbd..09de66c901b 100644
--- a/python/pyarrow/compute.py
+++ b/python/pyarrow/compute.py
@@ -34,7 +34,6 @@ from pyarrow._compute import ( # noqa
CastOptions,
CountOptions,
CumulativeOptions,
- CumulativeSumOptions,
DayOfWeekOptions,
DictionaryEncodeOptions,
RunEndEncodeOptions,
diff --git a/python/pyarrow/orc.py b/python/pyarrow/orc.py
index 8da0a2de797..aad47432cf0 100644
--- a/python/pyarrow/orc.py
+++ b/python/pyarrow/orc.py
@@ -17,9 +17,7 @@
from numbers import Integral
-import warnings
-from pyarrow.lib import Table
import pyarrow._orc as _orc
from pyarrow.fs import _resolve_filesystem_and_path
@@ -345,13 +343,6 @@ def write_table(table, where, *,
dictionary_key_size_threshold=0.0,
bloom_filter_columns=None,
bloom_filter_fpp=0.05):
- if isinstance(where, Table):
- warnings.warn(
- "The order of the arguments has changed. Pass as "
- "'write_table(table, where)' instead. The old order will raise "
- "an error in the future.", FutureWarning, stacklevel=2
- )
- table, where = where, table
with ORCWriter(
where,
file_version=file_version,
diff --git a/python/pyarrow/parquet/core.py b/python/pyarrow/parquet/core.py
index 4de88fe2299..253a8a33122 100644
--- a/python/pyarrow/parquet/core.py
+++ b/python/pyarrow/parquet/core.py
@@ -198,7 +198,7 @@ def filters_to_expression(filters):
_filters_to_expression = _deprecate_api(
"_filters_to_expression", "filters_to_expression",
- filters_to_expression, "10.0.0", DeprecationWarning)
+ filters_to_expression, "10.0.0", FutureWarning)
# ----------------------------------------------------------------------
diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index 2ac55a29202..30fff040fc3 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -74,14 +74,6 @@ cdef class ChunkedArray(_PandasConvertible):
self._assert_cpu()
return chunked_array, (self.chunks, self.type)
- @property
- def data(self):
- import warnings
- warnings.warn("Calling .data on ChunkedArray is provided for "
- "compatibility after Column was removed, simply drop "
- "this attribute", FutureWarning)
- return self
-
@property
def type(self):
"""
@@ -167,23 +159,6 @@ cdef class ChunkedArray(_PandasConvertible):
return frombytes(result, safe=True)
- def format(self, **kwargs):
- """
- DEPRECATED, use pyarrow.ChunkedArray.to_string
-
- Parameters
- ----------
- **kwargs : dict
-
- Returns
- -------
- str
- """
- import warnings
- warnings.warn('ChunkedArray.format is deprecated, '
- 'use ChunkedArray.to_string')
- return self.to_string(**kwargs)
-
def __str__(self):
return self.to_string()
@@ -3528,14 +3503,6 @@ cdef class RecordBatch(_Tabular):
else:
num_rows = 0
- if isinstance(names, Schema):
- import warnings
- warnings.warn("Schema passed to names= option, please "
- "pass schema= explicitly. "
- "Will raise exception in future", FutureWarning)
- schema = names
- names = None
-
converted_arrays = _sanitize_arrays(arrays, names, schema, metadata,
&c_schema)
@@ -6278,7 +6245,7 @@ def table(data, names=None, schema=None, metadata=None,
nthreads=None):
"Expected pandas DataFrame, python dictionary or list of arrays")
-def concat_tables(tables, MemoryPool memory_pool=None, str
promote_options="none", **kwargs):
+def concat_tables(tables, MemoryPool memory_pool=None, str
promote_options="none"):
"""
Concatenate pyarrow.Table objects.
@@ -6306,7 +6273,6 @@ def concat_tables(tables, MemoryPool memory_pool=None,
str promote_options="none
For memory allocations, if required, otherwise use default pool.
promote_options : str, default none
Accepts strings "none", "default" and "permissive".
- **kwargs : dict, optional
Examples
--------
@@ -6336,13 +6302,6 @@ def concat_tables(tables, MemoryPool memory_pool=None,
str promote_options="none
CConcatenateTablesOptions options = (
CConcatenateTablesOptions.Defaults())
- if "promote" in kwargs:
- warnings.warn(
- "promote has been superseded by promote_options='default'.",
- FutureWarning, stacklevel=2)
- if kwargs['promote'] is True:
- promote_options = "default"
-
for table in tables:
c_tables.push_back(table.sp_table)
diff --git a/python/pyarrow/tests/parquet/test_basic.py
b/python/pyarrow/tests/parquet/test_basic.py
index 8b91090989a..ce8c75f3c10 100644
--- a/python/pyarrow/tests/parquet/test_basic.py
+++ b/python/pyarrow/tests/parquet/test_basic.py
@@ -1075,3 +1075,17 @@ def
test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, sourc
with pytest.raises(ValueError, match="the 'source' argument"):
pq.read_table(source=source)
+
+
[email protected]
+def test_filters_to_expression_deprecated_alias():
+ # GH-49153: ``_filters_to_expression`` is kept for a few more releases
+ # as a FutureWarning-emitting alias of ``filters_to_expression``.
+ import pyarrow.dataset as ds
+
+ filters = [("a", "==", 1)]
+ expected = pq.filters_to_expression(filters)
+ with pytest.warns(FutureWarning, match="_filters_to_expression is
deprecated"):
+ result = pq._filters_to_expression(filters)
+ assert isinstance(result, ds.Expression)
+ assert result.equals(expected)
diff --git a/python/pyarrow/tests/test_array.py
b/python/pyarrow/tests/test_array.py
index 74ff837e16e..63c0eb0bea4 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -1808,12 +1808,6 @@ def test_cast_chunked_array_empty():
assert result.equals(expected)
-def test_chunked_array_data_warns():
- with pytest.warns(FutureWarning):
- res = pa.chunked_array([[]]).data
- assert isinstance(res, pa.ChunkedArray)
-
-
@pytest.mark.numpy
def test_cast_integers_unsafe():
# We let NumPy do the unsafe casting.
diff --git a/python/pyarrow/tests/test_compute.py
b/python/pyarrow/tests/test_compute.py
index d4d44e9347e..a8c2112d5e5 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -137,9 +137,6 @@ def test_exported_option_classes():
param.VAR_KEYWORD)
[email protected](
- "ignore:pyarrow.CumulativeSumOptions is deprecated as of 14.0"
-)
def test_option_class_equality(request):
options = [
pc.ArraySortOptions(),
@@ -226,12 +223,7 @@ def test_option_class_equality(request):
buf = option.serialize()
deserialized = pc.FunctionOptions.deserialize(buf)
assert option == deserialized
- # TODO remove the check under the if statement and the filterwarnings
- # mark when the deprecated class CumulativeSumOptions is removed.
- if repr(option).startswith("CumulativeSumOptions"):
- assert repr(deserialized).startswith("CumulativeOptions")
- else:
- assert repr(option) == repr(deserialized)
+ assert repr(option) == repr(deserialized)
for option1, option2 in zip(options, options[1:]):
assert option1 != option2
diff --git a/python/pyarrow/tests/test_orc.py b/python/pyarrow/tests/test_orc.py
index 27154a6f34f..b5b38006e5a 100644
--- a/python/pyarrow/tests/test_orc.py
+++ b/python/pyarrow/tests/test_orc.py
@@ -311,19 +311,9 @@ def test_buffer_readwrite():
assert orc_file.row_index_stride == 10000
assert orc_file.compression_size == 65536
- # deprecated keyword order
- buffer_output_stream = pa.BufferOutputStream()
- with pytest.warns(FutureWarning):
- orc.write_table(buffer_output_stream, table)
- buffer_reader = pa.BufferReader(buffer_output_stream.getvalue())
- orc_file = orc.ORCFile(buffer_reader)
- output_table = orc_file.read()
- assert table.equals(output_table)
- # Check for default WriteOptions
- assert orc_file.compression == 'UNCOMPRESSED'
- assert orc_file.file_version == '0.12'
- assert orc_file.row_index_stride == 10000
- assert orc_file.compression_size == 65536
+ # swapped argument order is no longer accepted
+ with pytest.raises(TypeError):
+ orc.write_table(pa.BufferOutputStream(), table)
@pytest.mark.snappy
@@ -352,27 +342,6 @@ def test_buffer_readwrite_with_writeoptions():
assert orc_file.row_index_stride == 5000
assert orc_file.compression_size == 65536
- # deprecated keyword order
- buffer_output_stream = pa.BufferOutputStream()
- with pytest.warns(FutureWarning):
- orc.write_table(
- buffer_output_stream,
- table,
- compression='uncompressed',
- file_version='0.11',
- row_index_stride=20000,
- compression_block_size=65536,
- )
- buffer_reader = pa.BufferReader(buffer_output_stream.getvalue())
- orc_file = orc.ORCFile(buffer_reader)
- output_table = orc_file.read()
- assert table.equals(output_table)
- # Check for default WriteOptions
- assert orc_file.compression == 'UNCOMPRESSED'
- assert orc_file.file_version == '0.11'
- assert orc_file.row_index_stride == 20000
- assert orc_file.compression_size == 65536
-
def test_buffer_readwrite_with_bad_writeoptions():
from pyarrow import orc
diff --git a/python/pyarrow/tests/test_pandas.py
b/python/pyarrow/tests/test_pandas.py
index 9421b345269..2391cb26000 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -4303,6 +4303,13 @@ def test_dictionary_from_pandas_specified_type():
with pytest.raises(pa.ArrowInvalid):
result = pa.array(cat, type=typ)
+ # mismatching values type that used to be ignored with a
+ # FutureWarning -> raise error
+ int_cat = pd.Categorical([1, 2, 1])
+ typ = pa.dictionary(index_type=pa.int8(), value_type=pa.string())
+ with pytest.raises(TypeError):
+ pa.array(int_cat, type=typ)
+
# mismatching order -> raise error
typ = pa.dictionary(
index_type=pa.int8(), value_type=pa.string(), ordered=True)
diff --git a/python/pyarrow/tests/test_schema.py
b/python/pyarrow/tests/test_schema.py
index b35b5350a81..01bf3c31a09 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -400,12 +400,8 @@ foo: list<item: int8>
assert sch[0].name == 'foo'
assert sch[0].type == fields[0].type
- with pytest.warns(FutureWarning):
- assert sch.field_by_name('bar') == fields[1]
- with pytest.warns(FutureWarning):
- assert sch.field_by_name('xxx') is None
- with pytest.warns((UserWarning, FutureWarning)):
- assert sch.field_by_name('foo') is None
+ assert not hasattr(sch, 'field_by_name')
+ assert not hasattr(sch, 'add_metadata')
# Schema::GetFieldIndex
assert sch.get_field_index('foo') == -1
diff --git a/python/pyarrow/tests/test_table.py
b/python/pyarrow/tests/test_table.py
index eb02051693f..b1af245be4b 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -2104,28 +2104,17 @@ def test_concat_tables_with_different_schema_metadata():
assert table2.schema.equals(table3.schema)
-def test_concat_tables_with_promote_option():
- t1 = pa.Table.from_arrays(
- [pa.array([1, 2], type=pa.int64())], ["int64_field"])
- t2 = pa.Table.from_arrays(
- [pa.array([1.0, 2.0], type=pa.float32())], ["float_field"])
-
- with pytest.warns(FutureWarning):
- result = pa.concat_tables([t1, t2], promote=True)
-
- assert result.equals(pa.Table.from_arrays([
- pa.array([1, 2, None, None], type=pa.int64()),
- pa.array([None, None, 1.0, 2.0], type=pa.float32()),
- ], ["int64_field", "float_field"]))
-
- t1 = pa.Table.from_arrays(
- [pa.array([1, 2], type=pa.int64())], ["f"])
- t2 = pa.Table.from_arrays(
- [pa.array([1, 2], type=pa.float32())], ["f"])
-
- with pytest.raises(pa.ArrowInvalid, match="Schema at index 1 was
different:"):
- with pytest.warns(FutureWarning):
- pa.concat_tables([t1, t2], promote=False)
+def test_concat_tables_removed_promote_option():
+ # The deprecated ``promote`` keyword was removed in favor of
+ # ``promote_options``. Use matching schemas so that the failure can only
+ # come from the rejected keyword, not from the concatenation itself.
+ t1 = pa.Table.from_arrays([pa.array([1, 2], type=pa.int64())], ["f"])
+ t2 = pa.Table.from_arrays([pa.array([3, 4], type=pa.int64())], ["f"])
+
+ with pytest.raises(TypeError, match="promote"):
+ pa.concat_tables([t1, t2], promote=True)
+ with pytest.raises(TypeError, match="promote"):
+ pa.concat_tables([t1, t2], promote=False)
def test_concat_tables_with_promotion():
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 4f1bb0f652b..c18bc2c9fa7 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -3211,35 +3211,6 @@ cdef class Schema(_Weakrefable):
cdef int index = <int> _normalize_index(i, self.schema.num_fields())
return pyarrow_wrap_field(self.schema.field(index))
- def field_by_name(self, name):
- """
- DEPRECATED
-
- Parameters
- ----------
- name : str
-
- Returns
- -------
- field: pyarrow.Field
- """
- cdef:
- vector[shared_ptr[CField]] results
-
- warnings.warn(
- "The 'field_by_name' method is deprecated, use 'field' instead",
- FutureWarning, stacklevel=2)
-
- results = self.schema.GetAllFieldsByName(tobytes(name))
- if results.size() == 0:
- return None
- elif results.size() > 1:
- warnings.warn("Schema field name corresponds to more "
- "than one field", UserWarning)
- return None
- else:
- return pyarrow_wrap_field(results[0])
-
def get_field_index(self, name):
"""
Return index of the unique field with the given name.
@@ -3453,19 +3424,6 @@ cdef class Schema(_Weakrefable):
return pyarrow_wrap_schema(new_schema)
- def add_metadata(self, metadata):
- """
- DEPRECATED
-
- Parameters
- ----------
- metadata : dict
- Keys and values must be string-like / coercible to bytes
- """
- warnings.warn("The 'add_metadata' method is deprecated, use "
- "'with_metadata' instead", FutureWarning, stacklevel=2)
- return self.with_metadata(metadata)
-
def with_metadata(self, metadata):
"""
Add metadata as dict of string keys and values to Schema