Skip to content

Commit

Permalink
GH-45296: [Python] Only enable the string dtype on pandas export for …
Browse files Browse the repository at this point in the history
…pandas>=2.3 (#45383)

The option already exists in pandas 2.2, but for that version our code does not work, so restricting it to pandas >= 2.3

* GitHub Issue: #45296

Authored-by: Joris Van den Bossche <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
  • Loading branch information
jorisvandenbossche authored and amoeba committed Jan 31, 2025
1 parent 6babc9a commit 2dd3954
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 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, _is_ge_v3
bint _is_v1, _is_ge_v21, _is_ge_v23, _is_ge_v3, _is_ge_v3_strict

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_v23 = self._loose_version >= Version('2.3.0')
self._is_ge_v3 = self._loose_version >= Version('3.0.0.dev0')

self._compat_module = pdcompat
Expand Down Expand Up @@ -170,10 +171,28 @@ cdef class _PandasAPIShim(object):
self._check_import()
return self._is_ge_v21

def is_ge_v23(self):
self._check_import()
return self._is_ge_v23

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

def is_ge_v3_strict(self):
self._check_import()
return self._is_ge_v3_strict

def uses_string_dtype(self):
if self.is_ge_v3_strict():
return True
try:
if self.is_ge_v23() and self.pd.options.future.infer_string:
return True
except:
pass
return False

@property
def categorical_type(self):
self._check_import()
Expand Down

0 comments on commit 2dd3954

Please sign in to comment.