Skip to content

Commit 7191763

Browse files
committed
BLD: Python changes to make meson build work
1 parent 90b4add commit 7191763

File tree

7 files changed

+76
-20
lines changed

7 files changed

+76
-20
lines changed

pandas/__init__.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,18 @@
176176
from pandas.util._tester import test
177177

178178
# use the closest tagged version if possible
179-
from pandas._version import get_versions
179+
_built_with_meson = False
180+
try:
181+
from pandas._version_meson import __version__, __git_version__
182+
183+
_built_with_meson = True
184+
except ImportError:
185+
from pandas._version import get_versions
180186

181-
v = get_versions()
182-
__version__ = v.get("closest-tag", v["version"])
183-
__git_version__ = v.get("full-revisionid")
184-
del get_versions, v
187+
v = get_versions()
188+
__version__ = v.get("closest-tag", v["version"])
189+
__git_version__ = v.get("full-revisionid")
190+
del get_versions, v
185191

186192
# GH 27101
187193
__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]

pandas/tests/api/test_api.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def check(self, namespace, expected, ignored=None):
2929
class TestPDApi(Base):
3030
# these are optionally imported based on testing
3131
# & need to be ignored
32-
ignored = ["tests", "locale", "conftest"]
32+
ignored = ["tests", "locale", "conftest", "_version_meson"]
3333

3434
# top-level sub-packages
3535
public_lib = [
@@ -43,7 +43,7 @@ class TestPDApi(Base):
4343
"io",
4444
"tseries",
4545
]
46-
private_lib = ["compat", "core", "pandas", "util"]
46+
private_lib = ["compat", "core", "pandas", "util", "_built_with_meson"]
4747

4848
# these are already deprecated; awaiting removal
4949
deprecated_modules: list[str] = ["np", "datetime"]
@@ -195,8 +195,9 @@ class TestPDApi(Base):
195195
"_is_numpy_dev",
196196
"_testing",
197197
"_typing",
198-
"_version",
199198
]
199+
if not pd._built_with_meson:
200+
private_modules.append("_version")
200201

201202
def test_api(self):
202203

@@ -316,8 +317,14 @@ def test_util_testing_deprecated_direct(self):
316317
assert "pandas.util.testing is deprecated" in str(m[0].message)
317318
assert "pandas.testing instead" in str(m[0].message)
318319

319-
def test_util_in_top_level(self):
320+
def test_util_in_top_level(self, monkeypatch):
320321
# in a subprocess to avoid import caching issues
322+
323+
# Can't import pandas from the test directory since its not
324+
# built inplace with meson
325+
if pd._built_with_meson:
326+
monkeypatch.chdir("..")
327+
321328
out = subprocess.check_output(
322329
[
323330
sys.executable,

pandas/tests/io/test_compression.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ def test_gzip_reproducibility_file_object():
201201
assert output == buffer.getvalue()
202202

203203

204-
def test_with_missing_lzma():
204+
def test_with_missing_lzma(monkeypatch):
205205
"""Tests if import pandas works when lzma is not present."""
206206
# https://github.com/pandas-dev/pandas/issues/27575
207+
# Can't import pandas from the test directory since its not
208+
# built inplace with meson
209+
if pd._built_with_meson:
210+
monkeypatch.chdir("..")
207211
code = textwrap.dedent(
208212
"""\
209213
import sys
@@ -214,10 +218,14 @@ def test_with_missing_lzma():
214218
subprocess.check_output([sys.executable, "-c", code], stderr=subprocess.PIPE)
215219

216220

217-
def test_with_missing_lzma_runtime():
221+
def test_with_missing_lzma_runtime(monkeypatch):
218222
"""Tests if RuntimeError is hit when calling lzma without
219223
having the module available.
220224
"""
225+
# Can't import pandas from the test directory since its not
226+
# built inplace with meson
227+
if pd._built_with_meson:
228+
monkeypatch.chdir("..")
221229
code = textwrap.dedent(
222230
"""
223231
import sys

pandas/tests/plotting/test_converter.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PeriodIndex,
1919
Series,
2020
Timestamp,
21+
_built_with_meson,
2122
arrays,
2223
date_range,
2324
)
@@ -45,8 +46,12 @@
4546
dates = pytest.importorskip("matplotlib.dates")
4647

4748

48-
def test_registry_mpl_resets():
49+
def test_registry_mpl_resets(monkeypatch):
4950
# Check that Matplotlib converters are properly reset (see issue #27481)
51+
# Can't import pandas from the test directory since its not
52+
# built inplace with meson
53+
if _built_with_meson:
54+
monkeypatch.chdir("..")
5055
code = (
5156
"import matplotlib.units as units; "
5257
"import matplotlib.dates as mdates; "
@@ -65,7 +70,11 @@ def test_timtetonum_accepts_unicode():
6570

6671

6772
class TestRegistration:
68-
def test_dont_register_by_default(self):
73+
def test_dont_register_by_default(self, monkeypatch):
74+
# Can't import pandas from the test directory since its not
75+
# built inplace with meson
76+
if _built_with_meson:
77+
monkeypatch.chdir("..")
6978
# Run in subprocess to ensure a clean state
7079
code = (
7180
"import matplotlib.units; "

pandas/tests/test_downstream.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,21 @@ def test_xarray_cftimeindex_nearest():
133133
assert result == expected
134134

135135

136-
def test_oo_optimizable():
136+
def test_oo_optimizable(monkeypatch):
137137
# GH 21071
138+
# Can't import pandas from the test directory since its not
139+
# built inplace with meson
140+
if pd._built_with_meson:
141+
monkeypatch.chdir("..")
138142
subprocess.check_call([sys.executable, "-OO", "-c", "import pandas"])
139143

140144

141-
def test_oo_optimized_datetime_index_unpickle():
145+
def test_oo_optimized_datetime_index_unpickle(monkeypatch):
142146
# GH 42866
147+
# Can't import pandas from the test directory since its not
148+
# built inplace with meson
149+
if pd._built_with_meson:
150+
monkeypatch.chdir("..")
143151
subprocess.check_call(
144152
[
145153
sys.executable,
@@ -270,7 +278,11 @@ def test_yaml_dump(df):
270278
tm.assert_frame_equal(df, loaded2)
271279

272280

273-
def test_missing_required_dependency():
281+
def test_missing_required_dependency(monkeypatch):
282+
# TODO: This test is basically disabled until we have
283+
# editable installs in meson-python. Re-enable this when
284+
# that happens.
285+
274286
# GH 23868
275287
# To ensure proper isolation, we pass these flags
276288
# -S : disable site-packages
@@ -283,6 +295,11 @@ def test_missing_required_dependency():
283295
# We skip this test if pandas is installed as a site package. We first
284296
# import the package normally and check the path to the module before
285297
# executing the test which imports pandas with site packages disabled.
298+
299+
# Can't import pandas from the test directory since its not
300+
# built inplace with meson
301+
if pd._built_with_meson:
302+
monkeypatch.chdir("..")
286303
call = [pyexe, "-c", "import pandas;print(pandas.__file__)"]
287304
output = subprocess.check_output(call).decode()
288305
if "site-packages" in output:

pandas/util/_print_versions.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ def _get_commit_hash() -> str | None:
2121
Use vendored versioneer code to get git hash, which handles
2222
git worktree correctly.
2323
"""
24-
from pandas._version import get_versions
24+
try:
25+
from pandas._version_meson import __git_version__
2526

26-
versions = get_versions()
27-
return versions["full-revisionid"]
27+
return __git_version__
28+
except ImportError:
29+
from pandas._version import get_versions
30+
31+
versions = get_versions()
32+
return versions["full-revisionid"]
2833

2934

3035
def _get_sys_info() -> dict[str, JSONSerializable]:

scripts/validate_min_versions_in_sync.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ def get_versions_from_ci(content: list[str]) -> tuple[dict[str, str], dict[str,
5858
elif "# optional dependencies" in line:
5959
seen_optional = True
6060
elif seen_required and line.strip():
61-
package, version = line.strip().split("=")
61+
try:
62+
package, version = line.strip().split("=")
63+
except ValueError:
64+
# pip dependencies, just skip
65+
continue
6266
package = package[2:]
6367
if package in EXCLUDE_DEPS:
6468
continue

0 commit comments

Comments
 (0)