Skip to content

Commit fad96e1

Browse files
TST: use env variable instead of pytest option for testing ArrayManager (#40222)
1 parent ad2ff04 commit fad96e1

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed

.github/workflows/ci.yml

+18-16
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,25 @@ jobs:
150150
uses: ./.github/actions/setup
151151

152152
- name: Run tests
153+
env:
154+
PANDAS_DATA_MANAGER: array
153155
run: |
154156
source activate pandas-dev
155-
pytest pandas/tests/frame/methods --array-manager
156-
pytest pandas/tests/frame/test_constructors.py --array-manager
157-
pytest pandas/tests/frame/constructors/ --array-manager
158-
pytest pandas/tests/frame/test_reductions.py --array-manager
159-
pytest pandas/tests/reductions/ --array-manager
160-
pytest pandas/tests/generic/test_generic.py --array-manager
161-
pytest pandas/tests/arithmetic/ --array-manager
162-
pytest pandas/tests/groupby/ --array-manager
163-
pytest pandas/tests/resample/ --array-manager
164-
pytest pandas/tests/reshape/merge --array-manager
157+
pytest pandas/tests/frame/methods
158+
pytest pandas/tests/frame/test_constructors.py
159+
pytest pandas/tests/frame/constructors/
160+
pytest pandas/tests/frame/test_reductions.py
161+
pytest pandas/tests/reductions/
162+
pytest pandas/tests/generic/test_generic.py
163+
pytest pandas/tests/arithmetic/
164+
pytest pandas/tests/groupby/
165+
pytest pandas/tests/resample/
166+
pytest pandas/tests/reshape/merge
165167
166168
# indexing subset (temporary since other tests don't pass yet)
167-
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager
168-
pytest pandas/tests/frame/indexing/test_where.py --array-manager
169-
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_multi_index --array-manager
170-
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns --array-manager
171-
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups --array-manager
172-
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column --array-manager
169+
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean
170+
pytest pandas/tests/frame/indexing/test_where.py
171+
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_multi_index
172+
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns
173+
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups
174+
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column

pandas/conftest.py

-13
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,6 @@ def pytest_addoption(parser):
100100
action="store_true",
101101
help="Fail if a test is skipped for missing data file.",
102102
)
103-
parser.addoption(
104-
"--array-manager",
105-
"--am",
106-
action="store_true",
107-
help="Use the experimental ArrayManager as default data manager.",
108-
)
109-
110-
111-
def pytest_sessionstart(session):
112-
# Note: we need to set the option here and not in pytest_runtest_setup below
113-
# to ensure this is run before creating fixture data
114-
if session.config.getoption("--array-manager"):
115-
pd.options.mode.data_manager = "array"
116103

117104

118105
def pytest_runtest_setup(item):

pandas/core/config_init.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
module is imported, register them here rather than in the module.
1010
1111
"""
12+
import os
1213
import warnings
1314

1415
import pandas._config.config as cf
@@ -483,18 +484,32 @@ def use_inf_as_na_cb(key):
483484
cf.register_option(
484485
"use_inf_as_null", False, use_inf_as_null_doc, cb=use_inf_as_na_cb
485486
)
486-
cf.register_option(
487-
"data_manager",
488-
"block",
489-
"Internal data manager type",
490-
validator=is_one_of_factory(["block", "array"]),
491-
)
487+
492488

493489
cf.deprecate_option(
494490
"mode.use_inf_as_null", msg=use_inf_as_null_doc, rkey="mode.use_inf_as_na"
495491
)
496492

497493

494+
data_manager_doc = """
495+
: string
496+
Internal data manager type; can be "block" or "array". Defaults to "block",
497+
unless overridden by the 'PANDAS_DATA_MANAGER' environment variable (needs
498+
to be set before pandas is imported).
499+
"""
500+
501+
502+
with cf.config_prefix("mode"):
503+
cf.register_option(
504+
"data_manager",
505+
# Get the default from an environment variable, if set, otherwise defaults
506+
# to "block". This environment variable can be set for testing.
507+
os.environ.get("PANDAS_DATA_MANAGER", "block"),
508+
data_manager_doc,
509+
validator=is_one_of_factory(["block", "array"]),
510+
)
511+
512+
498513
# user warnings
499514
chained_assignment = """
500515
: string

pandas/util/_test_decorators.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def test_foo():
3535
import numpy as np
3636
import pytest
3737

38+
from pandas._config import get_option
39+
3840
from pandas.compat import (
3941
IS64,
4042
is_platform_windows,
@@ -285,16 +287,11 @@ def async_mark():
285287
return async_mark
286288

287289

288-
# Note: we are using a string as condition (and not for example
289-
# `get_option("mode.data_manager") == "array"`) because this needs to be
290-
# evaluated at test time (otherwise this boolean condition gets evaluated
291-
# at import time, when the pd.options.mode.data_manager has not yet been set)
292-
293290
skip_array_manager_not_yet_implemented = pytest.mark.skipif(
294-
"config.getvalue('--array-manager')", reason="JSON C code relies on Blocks"
291+
get_option("mode.data_manager") == "array", reason="JSON C code relies on Blocks"
295292
)
296293

297294
skip_array_manager_invalid_test = pytest.mark.skipif(
298-
"config.getvalue('--array-manager')",
295+
get_option("mode.data_manager") == "array",
299296
reason="Test that relies on BlockManager internals or specific behaviour",
300297
)

0 commit comments

Comments
 (0)