8000 BUG Fixes fetch_kddcup99 for return_X_y and as_frame (#19011) · scikit-learn/scikit-learn@eedda91 · GitHub
[go: up one dir, main page]

Skip to content

Commit eedda91

Browse files
authored
BUG Fixes fetch_kddcup99 for return_X_y and as_frame (#19011)
1 parent 95128d3 commit eedda91

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sklearn/datasets/_kddcup99.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ def fetch_kddcup99(*, subset=None, data_home=None, shuffle=False,
199199
with open(join(module_path, 'descr', 'kddcup99.rst')) as rst_file:
200200
fdescr = rst_file.read()
201201

202-
if return_X_y:
203-
return data, target
204-
205202
frame = None
206203
if as_frame:
207204
frame, data, target = _convert_data_dataframe(
208205
"fetch_kddcup99", data, target, feature_names, target_names
209206
)
210207

208+
if return_X_y:
209+
return data, target
210+
211211
return Bunch(
212212
data=data,
213213
target=target,

sklearn/datasets/tests/test_common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def check_as_frame(bunch, dataset_func,
7575
if expected_target_dtype is not None:
7676
assert np.all(frame_bunch.target.dtypes == expected_target_dtype)
7777

78+
# Test for return_X_y and as_frame=True
79+
frame_X, frame_y = dataset_func(as_frame=True, return_X_y=True)
80+
assert isinstance(frame_X, pd.DataFrame)
81+
if frame_y.ndim > 1:
82+
assert isinstance(frame_X, pd.DataFrame)
83+
else:
84+
assert isinstance(frame_y, pd.Series)
85+
7886

7987
def _skip_network_tests():
8088
return os.environ.get('SKLEARN_SKIP_NETWORK_TESTS', '1') == '1'

0 commit comments

Comments
 (0)
0