Skip to content

Commit 49894b5

Browse files
Backport PR #65499 on branch 3.0.x (BUG: fix check if pyarrow is installed in cython lib - use existing constant) (#65501)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 1c6d1e3 commit 49894b5

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎pandas/_libs/lib.pyx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ from cython cimport (
4141
from pandas._config import using_string_dtype
4242

4343
from pandas._libs.missing import check_na_tuples_nonequal
44+
from pandas.compat import PYARROW_INSTALLED
4445
from pandas.util._decorators import set_module
4546

4647
import_datetime()
@@ -122,13 +123,12 @@ i8max = <int64_t>INT64_MAX
122123
u8max = <uint64_t>UINT64_MAX
123124

124125

125-
cdef bint PYARROW_INSTALLED = False
126+
cdef bint c_PYARROW_INSTALLED = PYARROW_INSTALLED
126127

127-
try:
128-
import pyarrow as pa
129128

130-
PYARROW_INSTALLED = True
131-
except ImportError:
129+
if c_PYARROW_INSTALLED:
130+
import pyarrow as pa
131+
else:
132132
pa = None
133133

134134

@@ -1326,7 +1326,7 @@ def is_pyarrow_array(obj):
13261326
-------
13271327
bool
13281328
"""
1329-
if PYARROW_INSTALLED:
1329+
if c_PYARROW_INSTALLED:
13301330
return isinstance(obj, (pa.Array, pa.ChunkedArray))
13311331
return False
13321332

‎pandas/compat/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from pandas.compat.numpy import is_numpy_dev
2828
from pandas.compat.pyarrow import (
2929
HAS_PYARROW,
30+
PYARROW_INSTALLED,
3031
PYARROW_MIN_VERSION,
3132
pa_version_under14p0,
3233
pa_version_under14p1,
@@ -160,6 +161,7 @@ def is_ci_environment() -> bool:
160161
"ISMUSL",
161162
"PY312",
162163
"PY314",
164+
"PYARROW_INSTALLED",
163165
"PYARROW_MIN_VERSION",
164166
"PYPY",
165167
"WASM",

‎pandas/compat/pyarrow.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
pa_version_under21p0 = _palv < Version("21.0.0")
2424
pa_version_under22p0 = _palv < Version("22.0.0")
2525
pa_version_under23p0 = _palv < Version("23.0.0")
26+
PYARROW_INSTALLED = True
2627
HAS_PYARROW = _palv >= Version(PYARROW_MIN_VERSION)
2728
except ImportError:
2829
pa_version_under14p0 = True
@@ -36,6 +37,7 @@
3637
pa_version_under21p0 = True
3738
pa_version_under22p0 = True
3839
pa_version_under23p0 = True
40+
PYARROW_INSTALLED = False
3941
HAS_PYARROW = False
4042

4143

0 commit comments

Comments
 (0)