This is an automated email from the ASF dual-hosted git repository.
jorisvandenbossche 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 c67d0260d4 GH-39732: [Python][CI] Fix test failures with
latest/nightly pandas (#39760)
c67d0260d4 is described below
commit c67d0260d4e96472b5cbdff66ca67ead2b9abe4c
Author: Alenka Frim <[email protected]>
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 <[email protected]>
Signed-off-by: Joris Van den Bossche <[email protected]>
---
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")