Skip to content

Commit 61c96ca

Browse files
authored
GH-49905: [Archery] Fix archery benchmark diff with pandas 3 (#49912)
### Rationale for this change Make archery benchmark diff work with pandas >= 3.0 ### What changes are included in this PR? Another way of patching the module ### Are these changes tested? Yes, locally running `archery benchmark diff` with both pandas 2 and 3 ### Are there any user-facing changes? No * GitHub Issue: #49905 Authored-by: AntoinePrv <AntoinePrv@users.noreply.github.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 23cd1ff commit 61c96ca

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

dev/archery/archery/compat.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pathlib
1919
import sys
20+
import types
2021

2122

2223
def _is_path_like(path):
@@ -47,8 +48,21 @@ def _stringify_path(path):
4748

4849

4950
def _import_pandas():
50-
# ARROW-13425: avoid importing PyArrow from Pandas
51-
sys.modules['pyarrow'] = None
51+
# ARROW-13425: hide the in-tree PyArrow from pandas so it doesn't try
52+
# to use a possibly-broken development build.
53+
# ARROW-49905: The original workaround sets ``sys.modules['pyarrow'] = None``,
54+
# but pandas >= 3.0 has a different import mechanism resulting in
55+
# ``AttributeError: 'NoneType' object has no attribute 'Array'``
56+
# on the first DataFrame construction (in ``pandas._libs.lib.is_pyarrow_array``).
57+
# Instead, we install a minimal stub where ``isinstance(obj, pa.Array)``
58+
# check returns False for every real object.
59+
if "pyarrow" not in sys.modules:
60+
stub = types.ModuleType("pyarrow")
61+
stub.Array = type("Array", (), {})
62+
stub.ChunkedArray = type("ChunkedArray", (), {})
63+
# pandas.compat.pyarrow parses ``pa.__version__`` at import time.
64+
stub.__version__ = "0.0.0"
65+
sys.modules["pyarrow"] = stub
5266
import pandas as pd
5367
return pd
5468

0 commit comments

Comments
 (0)