Skip to content

Commit a421648

Browse files
authored
MNT _convert_container "dataframe" -> "pandas" (scikit-learn#33956)
1 parent e02dfc4 commit a421648

17 files changed

Lines changed: 64 additions & 88 deletions

File tree

sklearn/datasets/tests/test_openml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def test_fetch_openml_sparse_arff_error(monkeypatch, params, err_msg):
10421042
@pytest.mark.parametrize(
10431043
"data_id, data_type",
10441044
[
1045-
(61, "dataframe"), # iris dataset version 1
1045+
(61, "pandas"), # iris dataset version 1
10461046
(292, "sparse"), # Australian dataset version 1
10471047
],
10481048
)
@@ -1052,7 +1052,7 @@ def test_fetch_openml_auto_mode(monkeypatch, data_id, data_type):
10521052

10531053
_monkey_patch_webbased_functions(monkeypatch, data_id, True)
10541054
data = fetch_openml(data_id=data_id, as_frame="auto", cache=False)
1055-
klass = pd.DataFrame if data_type == "dataframe" else scipy.sparse.csr_matrix
1055+
klass = pd.DataFrame if data_type == "pandas" else scipy.sparse.csr_matrix
10561056
assert isinstance(data.data, klass)
10571057

10581058

sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_predictions(global_random_seed, use_feature_names):
226226

227227
X = np.c_[f_a, f_0, f_b, f_1, f_c]
228228
columns_name = ["f_a", "f_0", "f_b", "f_1", "f_c"]
229-
constructor_name = "dataframe" if use_feature_names else "array"
229+
constructor_name = "pandas" if use_feature_names else "array"
230230
X = _convert_container(X, constructor_name, columns_name=columns_name)
231231

232232
noise = rng.normal(loc=0.0, scale=0.01, size=n_samples)

sklearn/impute/tests/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_base_no_precomputed_mask_transform(data):
9090
imputer.fit_transform(data)
9191

9292

93-
@pytest.mark.parametrize("X1_type", ["array", "dataframe"])
93+
@pytest.mark.parametrize("X1_type", ["array", "pandas"])
9494
def test_assign_where(X1_type):
9595
"""Check the behaviour of the private helpers `_assign_where`."""
9696
rng = np.random.RandomState(0)
@@ -102,6 +102,6 @@ def test_assign_where(X1_type):
102102

103103
_assign_where(X1, X2, mask)
104104

105-
if X1_type == "dataframe":
105+
if X1_type == "pandas":
106106
X1 = X1.to_numpy()
107107
assert_allclose(X1[mask], X2[mask])

sklearn/impute/tests/test_impute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ def test_imputation_mean_median_error_invalid_type(strategy, dtype):
286286

287287

288288
@pytest.mark.parametrize("strategy", ["mean", "median"])
289-
@pytest.mark.parametrize("type", ["list", "dataframe"])
290-
def test_imputation_mean_median_error_invalid_type_list_pandas(strategy, type):
289+
@pytest.mark.parametrize("constructor_name", ["list", "pandas"])
290+
def test_imputation_mean_median_error_invalid_type_list_pandas(
291+
strategy, constructor_name
292+
):
291293
X = [["a", "b", 3], [4, "e", 6], ["g", "h", 9]]
292-
if type == "dataframe":
293-
pd = pytest.importorskip("pandas")
294-
X = pd.DataFrame(X)
294+
X = _convert_container(X, constructor_name)
295295
msg = "non-numeric data:\ncould not convert string to float:"
296296
with pytest.raises(ValueError, match=msg):
297297
imputer = SimpleImputer(strategy=strategy)

sklearn/inspection/_plot/tests/test_plot_partial_dependence.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,17 @@ def test_plot_partial_dependence_kind(
178178
@pytest.mark.parametrize(
179179
"input_type, feature_names_type",
180180
[
181-
("dataframe", None),
182-
("dataframe", "list"),
181+
("pandas", None),
182+
("pandas", "list"),
183183
("list", "list"),
184184
("array", "list"),
185-
("dataframe", "array"),
185+
("pandas", "array"),
186186
("list", "array"),
187187
("array", "array"),
188-
("dataframe", "series"),
188+
("pandas", "series"),
189189
("list", "series"),
190190
("array", "series"),
191-
("dataframe", "index"),
191+
("pandas", "index"),
192192
("list", "index"),
193193
("array", "index"),
194194
],
@@ -205,13 +205,9 @@ def test_plot_partial_dependence_str_features(
205205
age = diabetes.data[:, diabetes.feature_names.index("age")]
206206
bmi = diabetes.data[:, diabetes.feature_names.index("bmi")]
207207

208-
if input_type == "dataframe":
209-
pd = pytest.importorskip("pandas")
210-
X = pd.DataFrame(diabetes.data, columns=diabetes.feature_names)
211-
elif input_type == "list":
212-
X = diabetes.data.tolist()
213-
else:
214-
X = diabetes.data
208+
X = _convert_container(
209+
diabetes.data, input_type, columns_name=diabetes.feature_names
210+
)
215211

216212
if feature_names_type is None:
217213
feature_names = None
@@ -803,7 +799,7 @@ def test_plot_partial_dependence_does_not_override_ylabel(
803799
@pytest.mark.parametrize(
804800
"categorical_features, array_type",
805801
[
806-
(["col_A", "col_C"], "dataframe"),
802+
(["col_A", "col_C"], "pandas"),
807803
([0, 2], "array"),
808804
([True, False, True], "array"),
809805
],
@@ -985,7 +981,7 @@ def test_partial_dependence_overwrite_labels(
985981
@pytest.mark.parametrize(
986982
"categorical_features, array_type",
987983
[
988-
(["col_A", "col_C"], "dataframe"),
984+
(["col_A", "col_C"], "pandas"),
989985
([0, 2], "array"),
990986
([True, False, True], "array"),
991987
],

sklearn/inspection/tests/test_pd_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"feature_names, array_type, expected_feature_names",
1010
[
1111
(None, "array", ["x0", "x1", "x2"]),
12-
(None, "dataframe", ["a", "b", "c"]),
12+
(None, "pandas", ["a", "b", "c"]),
1313
(np.array(["a", "b", "c"]), "array", ["a", "b", "c"]),
1414
],
1515
)

sklearn/inspection/tests/test_permutation_importance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def test_permutation_importance_equivalence_array_dataframe(n_jobs, max_samples)
369369
)
370370

371371

372-
@pytest.mark.parametrize("input_type", ["array", "dataframe"])
372+
@pytest.mark.parametrize("input_type", ["array", "pandas"])
373373
def test_permutation_importance_large_memmaped_data(input_type):
374374
# Smoke, non-regression test for:
375375
# https://github.com/scikit-learn/scikit-learn/issues/15810

sklearn/linear_model/tests/test_bayes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_ard_accuracy_on_easy_problem(global_random_seed, n_samples, n_features)
240240
assert abs_coef_error < 1e-10
241241

242242

243-
@pytest.mark.parametrize("constructor_name", ["array", "dataframe"])
243+
@pytest.mark.parametrize("constructor_name", ["array", "pandas"])
244244
def test_return_std(constructor_name, global_random_seed):
245245
# Test return_std option for both Bayesian regressors
246246
rng = np.random.RandomState(global_random_seed)

sklearn/preprocessing/tests/test_encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ def test_ohe_infrequent_user_cats_unknown_training_errors(kwargs):
13941394
@pytest.mark.parametrize(
13951395
"input_dtype, category_dtype", ["OO", "OU", "UO", "UU", "SO", "SU", "SS"]
13961396
)
1397-
@pytest.mark.parametrize("array_type", ["list", "array", "dataframe"])
1397+
@pytest.mark.parametrize("array_type", ["list", "array", "pandas"])
13981398
def test_encoders_string_categories(input_dtype, category_dtype, array_type):
13991399
"""Check that encoding work with object, unicode, and byte string dtypes.
14001400
Non-regression test for:

sklearn/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ class Estimator(BaseEstimator, WithSlots):
914914
@pytest.mark.parametrize(
915915
"constructor_name, minversion",
916916
[
917-
("dataframe", "1.5.0"),
917+
("pandas", "1.5.0"),
918918
("pyarrow", "13.0.0"),
919919
("polars", "0.20.23"),
920920
],

0 commit comments

Comments
 (0)