Skip to content

Commit 485cc45

Browse files
Merge remote-tracking branch 'upstream/master' into am-more-tests
2 parents e7209aa + fad96e1 commit 485cc45

28 files changed

+293
-307
lines changed

.github/workflows/ci.yml

+37-35
Original file line numberDiff line numberDiff line change
@@ -150,42 +150,44 @@ 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
165-
166-
pytest pandas/tests/series/methods --array-manager
167-
pytest pandas/tests/series/test_* --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
167+
168+
pytest pandas/tests/series/methods
169+
pytest pandas/tests/series/test_*
168170
169171
# indexing subset (temporary since other tests don't pass yet)
170-
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager
171-
pytest pandas/tests/frame/indexing/test_where.py --array-manager
172-
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_multi_index --array-manager
173-
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns --array-manager
174-
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups --array-manager
175-
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column --array-manager
176-
177-
pytest pandas/tests/api/ --array-manager
178-
pytest pandas/tests/base/ --array-manager
179-
pytest pandas/tests/computation/ --array-manager
180-
pytest pandas/tests/config/ --array-manager
181-
pytest pandas/tests/dtypes/ --array-manager
182-
pytest pandas/tests/generic/ --array-manager
183-
pytest pandas/tests/indexes/ --array-manager
184-
pytest pandas/tests/libs/ --array-manager
185-
pytest pandas/tests/plotting/ --array-manager
186-
pytest pandas/tests/scalar/ --array-manager
187-
pytest pandas/tests/strings/ --array-manager
188-
pytest pandas/tests/tools/ --array-manager
189-
pytest pandas/tests/tseries/ --array-manager
190-
pytest pandas/tests/tslibs/ --array-manager
191-
pytest pandas/tests/util/ --array-manager
172+
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean
173+
pytest pandas/tests/frame/indexing/test_where.py
174+
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_multi_index
175+
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns
176+
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups
177+
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column
178+
179+
pytest pandas/tests/api/
180+
pytest pandas/tests/base/
181+
pytest pandas/tests/computation/
182+
pytest pandas/tests/config/
183+
pytest pandas/tests/dtypes/
184+
pytest pandas/tests/generic/
185+
pytest pandas/tests/indexes/
186+
pytest pandas/tests/libs/
187+
pytest pandas/tests/plotting/
188+
pytest pandas/tests/scalar/
189+
pytest pandas/tests/strings/
190+
pytest pandas/tests/tools/
191+
pytest pandas/tests/tseries/
192+
pytest pandas/tests/tslibs/
193+
pytest pandas/tests/util/

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/tests/apply/test_frame_apply.py

-9
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ def test_apply(float_frame):
3737
assert result[d] == expected
3838
assert result.index is float_frame.index
3939

40-
# invalid axis
41-
df = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=["a", "a", "c"])
42-
msg = "No axis named 2 for object type DataFrame"
43-
with pytest.raises(ValueError, match=msg):
44-
df.apply(lambda x: x, 2)
45-
4640
# GH 9573
4741
df = DataFrame({"c0": ["A", "A", "B", "B"], "c1": ["C", "C", "D", "D"]})
4842
result = df.apply(lambda ts: ts.astype("category"))
@@ -579,9 +573,6 @@ def test_applymap_na_ignore(float_frame):
579573
strlen_frame_with_na[mask] = pd.NA
580574
tm.assert_frame_equal(strlen_frame_na_ignore, strlen_frame_with_na)
581575

582-
with pytest.raises(ValueError, match="na_action must be .*Got 'abc'"):
583-
float_frame_with_na.applymap(lambda x: len(str(x)), na_action="abc")
584-
585576

586577
def test_applymap_box_timestamps():
587578
# GH 2689, GH 2627

pandas/tests/apply/test_invalid_arg.py

+78-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# 4. invalid result shape/type
77
# If your test does not fit into one of these categories, add to this list.
88

9+
from itertools import chain
910
import re
1011

1112
import numpy as np
1213
import pytest
1314

1415
from pandas import (
16+
Categorical,
1517
DataFrame,
1618
Series,
1719
date_range,
@@ -34,6 +36,19 @@ def test_result_type_error(result_type, int_frame_const_col):
3436
df.apply(lambda x: [1, 2, 3], axis=1, result_type=result_type)
3537

3638

39+
def test_apply_invalid_axis_value():
40+
df = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=["a", "a", "c"])
41+
msg = "No axis named 2 for object type DataFrame"
42+
with pytest.raises(ValueError, match=msg):
43+
df.apply(lambda x: x, 2)
44+
45+
46+
def test_applymap_invalid_na_action(float_frame):
47+
# GH 23803
48+
with pytest.raises(ValueError, match="na_action must be .*Got 'abc'"):
49+
float_frame.applymap(lambda x: len(str(x)), na_action="abc")
50+
51+
3752
def test_agg_raises():
3853
# GH 26513
3954
df = DataFrame({"A": [0, 1], "B": [1, 2]})
@@ -43,6 +58,28 @@ def test_agg_raises():
4358
df.agg()
4459

4560

61+
def test_map_with_invalid_na_action_raises():
62+
# https://github.com/pandas-dev/pandas/issues/32815
63+
s = Series([1, 2, 3])
64+
msg = "na_action must either be 'ignore' or None"
65+
with pytest.raises(ValueError, match=msg):
66+
s.map(lambda x: x, na_action="____")
67+
68+
69+
def test_map_categorical_na_action():
70+
values = Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True)
71+
s = Series(values, name="XX", index=list("abcdefg"))
72+
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
73+
s.map(lambda x: x, na_action="ignore")
74+
75+
76+
def test_map_datetimetz_na_action():
77+
values = date_range("2011-01-01", "2011-01-02", freq="H").tz_localize("Asia/Tokyo")
78+
s = Series(values, name="XX")
79+
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
80+
s.map(lambda x: x, na_action="ignore")
81+
82+
4683
@pytest.mark.parametrize("box", [DataFrame, Series])
4784
@pytest.mark.parametrize("method", ["apply", "agg", "transform"])
4885
@pytest.mark.parametrize("func", [{"A": {"B": "sum"}}, {"A": {"B": ["sum"]}}])
@@ -54,6 +91,22 @@ def test_nested_renamer(box, method, func):
5491
getattr(obj, method)(func)
5592

5693

94+
def test_series_agg_nested_renamer():
95+
s = Series(range(6), dtype="int64", name="series")
96+
msg = "nested renamer is not supported"
97+
with pytest.raises(SpecificationError, match=msg):
98+
s.agg({"foo": ["min", "max"]})
99+
100+
101+
def test_multiple_aggregators_with_dict_api():
102+
103+
s = Series(range(6), dtype="int64", name="series")
104+
# nested renaming
105+
msg = "nested renamer is not supported"
106+
with pytest.raises(SpecificationError, match=msg):
107+
s.agg({"foo": ["min", "max"], "bar": ["sum", "mean"]})
108+
109+
57110
def test_transform_nested_renamer():
58111
# GH 35964
59112
match = "nested renamer is not supported"
@@ -208,13 +261,37 @@ def transform2(row):
208261
DataFrame([["a", "b"], ["b", "a"]]), [["cumprod", TypeError]]
209262
),
210263
)
211-
def test_agg_cython_table_raises(df, func, expected, axis):
264+
def test_agg_cython_table_raises_frame(df, func, expected, axis):
212265
# GH 21224
213266
msg = "can't multiply sequence by non-int of type 'str'"
214267
with pytest.raises(expected, match=msg):
215268
df.agg(func, axis=axis)
216269

217270

271+
@pytest.mark.parametrize(
272+
"series, func, expected",
273+
chain(
274+
tm.get_cython_table_params(
275+
Series("a b c".split()),
276+
[
277+
("mean", TypeError), # mean raises TypeError
278+
("prod", TypeError),
279+
("std", TypeError),
280+
("var", TypeError),
281+
("median", TypeError),
282+
("cumprod", TypeError),
283+
],
284+
)
285+
),
286+
)
287+
def test_agg_cython_table_raises_series(series, func, expected):
288+
# GH21224
289+
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
290+
with pytest.raises(expected, match=msg):
291+
# e.g. Series('a b'.split()).cumprod() will raise
292+
series.agg(func)
293+
294+
218295
def test_transform_none_to_type():
219296
# GH#34377
220297
df = DataFrame({"a": [None]})

pandas/tests/apply/test_series_apply.py

-53
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
timedelta_range,
2121
)
2222
import pandas._testing as tm
23-
from pandas.core.base import SpecificationError
2423

2524

2625
def test_series_map_box_timedelta():
@@ -269,20 +268,6 @@ def test_demo():
269268
expected = Series([0], index=["foo"], name="series")
270269
tm.assert_series_equal(result, expected)
271270

272-
# nested renaming
273-
msg = "nested renamer is not supported"
274-
with pytest.raises(SpecificationError, match=msg):
275-
s.agg({"foo": ["min", "max"]})
276-
277-
278-
def test_multiple_aggregators_with_dict_api():
279-
280-
s = Series(range(6), dtype="int64", name="series")
281-
# nested renaming
282-
msg = "nested renamer is not supported"
283-
with pytest.raises(SpecificationError, match=msg):
284-
s.agg({"foo": ["min", "max"], "bar": ["sum", "mean"]})
285-
286271

287272
def test_agg_apply_evaluate_lambdas_the_same(string_series):
288273
# test that we are evaluating row-by-row first
@@ -439,30 +424,6 @@ def test_agg_cython_table_transform(series, func, expected):
439424
tm.assert_series_equal(result, expected)
440425

441426

442-
@pytest.mark.parametrize(
443-
"series, func, expected",
444-
chain(
445-
tm.get_cython_table_params(
446-
Series("a b c".split()),
447-
[
448-
("mean", TypeError), # mean raises TypeError
449-
("prod", TypeError),
450-
("std", TypeError),
451-
("var", TypeError),
452-
("median", TypeError),
453-
("cumprod", TypeError),
454-
],
455-
)
456-
),
457-
)
458-
def test_agg_cython_table_raises(series, func, expected):
459-
# GH21224
460-
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
461-
with pytest.raises(expected, match=msg):
462-
# e.g. Series('a b'.split()).cumprod() will raise
463-
series.agg(func)
464-
465-
466427
def test_series_apply_no_suffix_index():
467428
# GH36189
468429
s = Series([4] * 3)
@@ -732,9 +693,6 @@ def test_map_categorical():
732693
tm.assert_series_equal(result, exp)
733694
assert result.dtype == object
734695

735-
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
736-
s.map(lambda x: x, na_action="ignore")
737-
738696

739697
def test_map_datetimetz():
740698
values = pd.date_range("2011-01-01", "2011-01-02", freq="H").tz_localize(
@@ -756,9 +714,6 @@ def test_map_datetimetz():
756714
exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64)
757715
tm.assert_series_equal(result, exp)
758716

759-
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
760-
s.map(lambda x: x, na_action="ignore")
761-
762717
# not vectorized
763718
def f(x):
764719
if not isinstance(x, pd.Timestamp):
@@ -827,14 +782,6 @@ def test_map_float_to_string_precision():
827782
assert result == expected
828783

829784

830-
def test_map_with_invalid_na_action_raises():
831-
# https://github.com/pandas-dev/pandas/issues/32815
832-
s = Series([1, 2, 3])
833-
msg = "na_action must either be 'ignore' or None"
834-
with pytest.raises(ValueError, match=msg):
835-
s.map(lambda x: x, na_action="____")
836-
837-
838785
def test_apply_to_timedelta():
839786
list_of_valid_strings = ["00:00:01", "00:00:02"]
840787
a = pd.to_timedelta(list_of_valid_strings)

0 commit comments

Comments
 (0)