Skip to content

Commit 2dd3954

Browse files
jorisvandenbosscheamoeba
authored andcommitted
GH-45296: [Python] Only enable the string dtype on pandas export for 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]>
1 parent 6babc9a commit 2dd3954

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

python/pyarrow/pandas-shim.pxi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cdef class _PandasAPIShim(object):
3838
object _array_like_types, _is_extension_array_dtype, _lock
3939
bint has_sparse
4040
bint _pd024
41-
bint _is_v1, _is_ge_v21, _is_ge_v3
41+
bint _is_v1, _is_ge_v21, _is_ge_v23, _is_ge_v3, _is_ge_v3_strict
4242

4343
def __init__(self):
4444
self._lock = Lock()
@@ -79,6 +79,7 @@ cdef class _PandasAPIShim(object):
7979

8080
self._is_v1 = self._loose_version < Version('2.0.0')
8181
self._is_ge_v21 = self._loose_version >= Version('2.1.0')
82+
self._is_ge_v23 = self._loose_version >= Version('2.3.0')
8283
self._is_ge_v3 = self._loose_version >= Version('3.0.0.dev0')
8384

8485
self._compat_module = pdcompat
@@ -170,10 +171,28 @@ cdef class _PandasAPIShim(object):
170171
self._check_import()
171172
return self._is_ge_v21
172173

174+
def is_ge_v23(self):
175+
self._check_import()
176+
return self._is_ge_v23
177+
173178
def is_ge_v3(self):
174179
self._check_import()
175180
return self._is_ge_v3
176181

182+
def is_ge_v3_strict(self):
183+
self._check_import()
184+
return self._is_ge_v3_strict
185+
186+
def uses_string_dtype(self):
187+
if self.is_ge_v3_strict():
188+
return True
189+
try:
190+
if self.is_ge_v23() and self.pd.options.future.infer_string:
191+
return True
192+
except:
193+
pass
194+
return False
195+
177196
@property
178197
def categorical_type(self):
179198
self._check_import()

0 commit comments

Comments
 (0)