diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index b65dac4cba4..5e6078b7254 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -1551,9 +1551,8 @@ def record_batch(data, names=None, schema=None, metadata=None): Parameters ---------- - data : pandas.DataFrame, dict, list - A DataFrame, mapping of strings to Arrays or Python lists, or list of - arrays or chunked arrays + data : pandas.DataFrame, list + A DataFrame or list of arrays or chunked arrays. names : list, default None Column names if list of arrays passed as data. Mutually exclusive with 'schema' argument @@ -1569,7 +1568,7 @@ def record_batch(data, names=None, schema=None, metadata=None): See Also -------- - RecordBatch.from_arrays, RecordBatch.from_pandas, Table.from_pydict + RecordBatch.from_arrays, RecordBatch.from_pandas, table """ # accept schema as first argument for backwards compatibility / usability if isinstance(names, Schema) and schema is None: @@ -1579,10 +1578,10 @@ def record_batch(data, names=None, schema=None, metadata=None): if isinstance(data, (list, tuple)): return RecordBatch.from_arrays(data, names=names, schema=schema, metadata=metadata) - elif isinstance(data, _pandas_api.pd.DataFrame): + elif _pandas_api.is_data_frame(data): return RecordBatch.from_pandas(data, schema=schema) else: - return TypeError("Expected pandas DataFrame or python dictionary") + raise TypeError("Expected pandas DataFrame or list of arrays") def table(data, names=None, schema=None, metadata=None): @@ -1628,7 +1627,7 @@ def table(data, names=None, schema=None, metadata=None): raise ValueError( "The 'names' argument is not valid when passing a dictionary") return Table.from_pydict(data, schema=schema, metadata=metadata) - elif isinstance(data, _pandas_api.pd.DataFrame): + 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 " diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index 6fe7ba3baaa..3649405d5c6 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -1183,10 +1183,13 @@ def test_table_factory_function_args_pandas(): assert table.column('a').type == pa.int32() -def test_table_factory_function_invalid_input(): +def test_factory_functions_invalid_input(): with pytest.raises(TypeError, match="Expected pandas DataFrame, python"): pa.table("invalid input") + with pytest.raises(TypeError, match="Expected pandas DataFrame"): + pa.record_batch("invalid input") + def test_table_function_unicode_schema(): col_a = "äääh"