Skip to content

Commit

Permalink
apacheGH-39732: [Python][CI] Fix test failures with latest/nightly pa…
Browse files Browse the repository at this point in the history
…ndas (apache#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: apache#39732

Authored-by: AlenkaF <frim.alenka@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
  • Loading branch information
AlenkaF authored and zanmato1984 committed Feb 28, 2024
1 parent 2a1b245 commit 307630c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down

0 comments on commit 307630c

Please sign in to comment.