|
51 | 51 | "test_clone",
|
52 | 52 | "test_clone_2",
|
53 | 53 | "test_clone_raises_error_for_nonconforming_objects",
|
54 |
| - "test_clone_param_is_none", |
55 |
| - "test_clone_empty_array", |
56 |
| - "test_clone_sparse_matrix", |
57 |
| - "test_clone_nan", |
| 54 | + "test_clone_none_and_empty_array_nan_sparse_matrix", |
58 | 55 | "test_clone_estimator_types",
|
59 | 56 | "test_clone_class_rather_than_instance_raises_error",
|
60 | 57 | "test_clone_sklearn_composite",
|
@@ -1025,75 +1022,30 @@ def __init__(self, obj, obj_iterable):
|
1025 | 1022 | not _check_soft_dependencies("scikit-learn", severity="none"),
|
1026 | 1023 | reason="skip test if sklearn is not available",
|
1027 | 1024 | ) # sklearn is part of the dev dependency set, test should be executed with that
|
1028 |
| -def test_clone_param_is_none(fixture_class_parent: Type[Parent]): |
1029 |
| - """Test clone with keyword parameter set to None.""" |
1030 |
| - from sklearn.base import clone |
1031 |
| - |
1032 |
| - base_obj = fixture_class_parent(c=None) |
1033 |
| - new_base_obj = clone(base_obj) |
1034 |
| - new_base_obj2 = base_obj.clone() |
1035 |
| - assert base_obj.c is new_base_obj.c |
1036 |
| - assert base_obj.c is new_base_obj2.c |
1037 |
| - |
1038 |
| - |
1039 |
| -@pytest.mark.skipif( |
1040 |
| - not _check_soft_dependencies("scikit-learn", severity="none"), |
1041 |
| - reason="skip test if sklearn is not available", |
1042 |
| -) # sklearn is part of the dev dependency set, test should be executed with that |
1043 |
| -def test_clone_empty_array(fixture_class_parent: Type[Parent]): |
1044 |
| - """Test clone with keyword parameter is scipy sparse matrix. |
1045 |
| -
|
1046 |
| - This test is based on scikit-learn regression test to make sure clone |
1047 |
| - works with default parameter set to scipy sparse matrix. |
1048 |
| - """ |
1049 |
| - from sklearn.base import clone |
1050 |
| - |
1051 |
| - # Regression test for cloning estimators with empty arrays |
1052 |
| - base_obj = fixture_class_parent(c=np.array([])) |
1053 |
| - new_base_obj = clone(base_obj) |
1054 |
| - new_base_obj2 = base_obj.clone() |
1055 |
| - np.testing.assert_array_equal(base_obj.c, new_base_obj.c) |
1056 |
| - np.testing.assert_array_equal(base_obj.c, new_base_obj2.c) |
1057 |
| - |
1058 |
| - |
1059 |
| -@pytest.mark.skipif( |
1060 |
| - not _check_soft_dependencies("scikit-learn", severity="none"), |
1061 |
| - reason="skip test if sklearn is not available", |
1062 |
| -) # sklearn is part of the dev dependency set, test should be executed with that |
1063 |
| -def test_clone_sparse_matrix(fixture_class_parent: Type[Parent]): |
1064 |
| - """Test clone with keyword parameter is scipy sparse matrix. |
1065 |
| -
|
1066 |
| - This test is based on scikit-learn regression test to make sure clone |
1067 |
| - works with default parameter set to scipy sparse matrix. |
1068 |
| - """ |
1069 |
| - from sklearn.base import clone |
1070 |
| - |
1071 |
| - base_obj = fixture_class_parent(c=sp.csr_matrix(np.array([[0]]))) |
1072 |
| - new_base_obj = clone(base_obj) |
1073 |
| - new_base_obj2 = base_obj.clone() |
1074 |
| - np.testing.assert_array_equal(base_obj.c, new_base_obj.c) |
1075 |
| - np.testing.assert_array_equal(base_obj.c, new_base_obj2.c) |
1076 |
| - |
1077 |
| - |
1078 |
| -@pytest.mark.skipif( |
1079 |
| - not _check_soft_dependencies("scikit-learn", severity="none"), |
1080 |
| - reason="skip test if sklearn is not available", |
1081 |
| -) # sklearn is part of the dev dependency set, test should be executed with that |
1082 |
| -def test_clone_nan(fixture_class_parent: Type[Parent]): |
1083 |
| - """Test clone with keyword parameter is np.nan. |
1084 |
| -
|
1085 |
| - This test is based on scikit-learn regression test to make sure clone |
1086 |
| - works with default parameter set to np.nan. |
1087 |
| - """ |
| 1025 | +@pytest.mark.parametrize( |
| 1026 | + "c_value", |
| 1027 | + [ |
| 1028 | + None, |
| 1029 | + np.array([]), |
| 1030 | + sp.csr_matrix(np.array([[0]])), |
| 1031 | + np.nan, |
| 1032 | + ], |
| 1033 | +) |
| 1034 | +def test_clone_none_and_empty_array_nan_sparse_matrix( |
| 1035 | + fixture_class_parent: Type[Parent], c_value |
| 1036 | +): |
1088 | 1037 | from sklearn.base import clone
|
1089 | 1038 |
|
1090 |
| - # Regression test for cloning estimators with default parameter as np.nan |
1091 |
| - base_obj = fixture_class_parent(c=np.nan) |
| 1039 | + base_obj = fixture_class_parent(c=c_value) |
1092 | 1040 | new_base_obj = clone(base_obj)
|
1093 | 1041 | new_base_obj2 = base_obj.clone()
|
1094 | 1042 |
|
1095 |
| - assert base_obj.c is new_base_obj.c |
1096 |
| - assert base_obj.c is new_base_obj2.c |
| 1043 | + if isinstance(base_obj.c, (np.ndarray, type(sp.csr_matrix(np.array([[0]]))))): |
| 1044 | + np.testing.assert_array_equal(base_obj.c, new_base_obj.c) |
| 1045 | + np.testing.assert_array_equal(base_obj.c, new_base_obj2.c) |
| 1046 | + else: |
| 1047 | + assert base_obj.c is new_base_obj.c |
| 1048 | + assert base_obj.c is new_base_obj2.c |
1097 | 1049 |
|
1098 | 1050 |
|
1099 | 1051 | def test_clone_estimator_types(fixture_class_parent: Type[Parent]):
|
|
0 commit comments