-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure make_classification respects output type (#3415)
Switch to api_return_generic decorator in order to get correct output type from make_classification Provide tests of global_output_type compliance for all dataset generators Authors: - William Hicks (@wphicks) Approvers: - John Zedlewski (@JohnZed) - Corey J. Nolet (@cjnolet) URL: #3415
- Loading branch information
Showing
3 changed files
with
73 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# | ||
# Copyright (c) 2021, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import cudf | ||
import cupy as cp | ||
import numba | ||
import numpy as np | ||
import pytest | ||
|
||
import cuml | ||
from cuml.datasets import ( | ||
make_arima, | ||
make_blobs, | ||
make_classification, | ||
make_regression | ||
) | ||
|
||
|
||
TEST_OUTPUT_TYPES = ( | ||
(None, (cp.ndarray, cp.ndarray)), # Default is cupy if None is used | ||
('numpy', (np.ndarray, np.ndarray)), | ||
('cupy', (cp.ndarray, cp.ndarray)), | ||
('numba', (numba.cuda.devicearray.DeviceNDArrayBase, | ||
numba.cuda.devicearray.DeviceNDArrayBase)), | ||
('cudf', (cudf.DataFrame, cudf.Series)) | ||
) | ||
|
||
GENERATORS = ( | ||
make_blobs, make_classification, make_regression | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('generator', GENERATORS) | ||
@pytest.mark.parametrize( | ||
'output_str,output_types', TEST_OUTPUT_TYPES | ||
) | ||
def test_xy_output_type(generator, output_str, output_types): | ||
|
||
# Set the output type and ensure data of that type is generated | ||
with cuml.using_output_type(output_str): | ||
data = generator(n_samples=10, random_state=0) | ||
|
||
for data, type_ in zip(data, output_types): | ||
assert isinstance(data, type_) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'output_str,output_types', TEST_OUTPUT_TYPES | ||
) | ||
def test_time_series_label_output_type(output_str, output_types): | ||
|
||
# Set the output type and ensure data of that type is generated | ||
with cuml.using_output_type(output_str): | ||
data = make_arima(n_obs=10, random_state=0)[0] | ||
|
||
assert isinstance(data, output_types[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters