You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ra...@apache.org on 2024/02/20 11:21:25 UTC
(arrow) 13/30: GH-39732: [Python][CI] Fix test failures with latest/nightly pandas (#39760)
This is an automated email from the ASF dual-hosted git repository.
raulcd pushed a commit to branch maint-15.0.x
in repository https://gitbox.apache.org/repos/asf/arrow.git
commit 5e8e20de3cdf697230651f729475d7795106ab2a
Author: Alenka Frim <Al...@users.noreply.github.com>
AuthorDate: Thu Jan 25 10:21:57 2024 +0100
GH-39732: [Python][CI] Fix test failures with latest/nightly pandas (#39760)
This PR rearranges if-else blocks in the `table` function (`table.pxi`) so that pandas dataframe object comes before checking for `__arrow_c_stream__` and `__arrow_c_array__`.
* Closes: #39732
Authored-by: AlenkaF <fr...@gmail.com>
Signed-off-by: Joris Van den Bossche <jo...@gmail.com>
---
python/pyarrow/table.pxi | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index d98c93e1c0..3c450d61a7 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -5202,7 +5202,17 @@ def table(data, names=None, schema=None, metadata=None, nthreads=None):
raise ValueError(
"The 'names' argument is not valid when passing a dictionary")
return Table.from_pydict(data, schema=schema, metadata=metadata)
+ elif _pandas_api.is_data_frame(data):
+ if names is not None or metadata is not None:
+ raise ValueError(
+ "The 'names' and 'metadata' arguments are not valid when "
+ "passing a pandas DataFrame")
+ return Table.from_pandas(data, schema=schema, nthreads=nthreads)
elif hasattr(data, "__arrow_c_stream__"):
+ if names is not None or metadata is not None:
+ raise ValueError(
+ "The 'names' and 'metadata' arguments are not valid when "
+ "using Arrow PyCapsule Interface")
if schema is not None:
requested = schema.__arrow_c_schema__()
else:
@@ -5216,14 +5226,12 @@ def table(data, names=None, schema=None, metadata=None, nthreads=None):
table = table.cast(schema)
return table
elif hasattr(data, "__arrow_c_array__"):
- batch = record_batch(data, schema)
- return Table.from_batches([batch])
- elif _pandas_api.is_data_frame(data):
if names is not None or metadata is not None:
raise ValueError(
"The 'names' and 'metadata' arguments are not valid when "
- "passing a pandas DataFrame")
- return Table.from_pandas(data, schema=schema, nthreads=nthreads)
+ "using Arrow PyCapsule Interface")
+ batch = record_batch(data, schema)
+ return Table.from_batches([batch])
else:
raise TypeError(
"Expected pandas DataFrame, python dictionary or list of arrays")