Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Apr 11, 2024
1 parent 3dd79ff commit 388bfcc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
5 changes: 0 additions & 5 deletions python/benchmarks/convert_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,3 @@ def setup(self):
def time_Table_from_pandas(self):
for _ in range(50):
pa.Table.from_pandas(self.df, nthreads=1)


class ArrowTableToPandasDataframe():


6 changes: 2 additions & 4 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,7 @@ cdef class _PandasConvertible(_Weakrefable):
bint self_destruct=False,
str maps_as_pydicts=None,
types_mapper=None,
bint coerce_temporal_nanoseconds=False,
bint use_blocks=True,
bint coerce_temporal_nanoseconds=False
):
"""
Convert to a pandas-compatible NumPy array or DataFrame, as appropriate
Expand Down Expand Up @@ -868,8 +867,7 @@ cdef class _PandasConvertible(_Weakrefable):
split_blocks=split_blocks,
self_destruct=self_destruct,
maps_as_pydicts=maps_as_pydicts,
coerce_temporal_nanoseconds=coerce_temporal_nanoseconds,
use_blocks=use_blocks,
coerce_temporal_nanoseconds=coerce_temporal_nanoseconds
)
return self._to_pandas(options, categories=categories,
ignore_metadata=ignore_metadata,
Expand Down
7 changes: 6 additions & 1 deletion python/pyarrow/pandas-shim.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef class _PandasAPIShim(object):
object _array_like_types, _is_extension_array_dtype, _lock
bint has_sparse
bint _pd024
bint _is_v1, _is_ge_v21
bint _is_v1, _is_ge_v21, _is_ge_v3

def __init__(self):
self._lock = Lock()
Expand Down Expand Up @@ -79,6 +79,7 @@ cdef class _PandasAPIShim(object):

self._is_v1 = self._loose_version < Version('2.0.0')
self._is_ge_v21 = self._loose_version >= Version('2.1.0')
self._is_ge_v3 = self._loose_version >= Version('3.0.0.dev0')

self._compat_module = pdcompat
self._data_frame = pd.DataFrame
Expand Down Expand Up @@ -169,6 +170,10 @@ cdef class _PandasAPIShim(object):
self._check_import()
return self._is_ge_v21

def is_ge_v3(self):
self._check_import()
return self._is_ge_v3

@property
def categorical_type(self):
self._check_import()
Expand Down
23 changes: 12 additions & 11 deletions python/pyarrow/pandas_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,18 @@ def table_to_dataframe(
column_names = table.column_names
result = pa.lib.table_to_blocks(options, table, categories,
list(ext_columns_dtypes.keys()))
if options["use_blocks"]:
if _pandas_api.is_ge_v3():
print("using new API")
from pandas.api.internals import create_dataframe_from_blocks

blocks = [
_reconstruct_block(
item, column_names, ext_columns_dtypes, return_block=False)
for item in result
]
df = create_dataframe_from_blocks(blocks, index=index, columns=columns)
return df
else:
from pandas.core.internals import BlockManager
from pandas import DataFrame

Expand All @@ -793,16 +804,6 @@ def table_to_dataframe(
else:
df = DataFrame(mgr)
return df
else:
from pandas.api.internals import create_dataframe_from_blocks

blocks = [
_reconstruct_block(
item, column_names, ext_columns_dtypes, return_block=False)
for item in result
]
df = create_dataframe_from_blocks(blocks, index=index, columns=columns)
return df


# Set of the string repr of all numpy dtypes that can be stored in a pandas
Expand Down

0 comments on commit 388bfcc

Please sign in to comment.