ETA444 / datasafari

DataSafari simplifies complex data science tasks into straightforward, powerful one-liners.
https://datasafari.dev
GNU General Public License v3.0
2 stars 0 forks source link

Construct tests for model_tuning_core() #114

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

Test Descriptions

  1. Type Error Tests:

    • Invalid x_train Type: Ensures a TypeError is raised when x_train is neither a DataFrame nor an ndarray.
    • Invalid y_train Type: Checks for a TypeError if y_train is not a Series or ndarray.
    • Invalid task_type: Verifies that providing a non-string task_type raises a TypeError, and an incorrect string raises a ValueError.
    • Invalid models Type: Asserts a TypeError is raised if models is not a dictionary.
    • Invalid priority_metrics Type: Checks for a TypeError when priority_metrics is not a list.
    • Invalid priority_tuners Type: Verifies a TypeError for non-list priority_tuners.
    • Invalid custom_param_grids Type: Asserts a TypeError if custom_param_grids is not a dictionary.
    • Invalid n_jobs, cv, verbose, and random_state Types: Ensures TypeErrors are raised if these parameters are not integers.
    • Invalid cv Value: Confirms a ValueError if cv is less than 1.
    • Invalid Iteration Values: Checks for ValueErrors when n_iter_random or n_iter_bayesian are less than 1.
  2. Value Error Tests:

    • Mismatched x_train and y_train Shapes: Ensures a ValueError is raised if x_train and y_train do not have compatible shapes.
    • Empty x_train or y_train: Confirms ValueErrors are raised if x_train or y_train are empty.
    • Duplicate or Invalid priority_metrics: Verifies that ValueErrors are raised for duplicate values or invalid metric names in priority_metrics.
    • Incompatible Metrics for Task Type: Checks for ValueErrors if metrics not suitable for the specified task_type are provided.
    • Excessive n_top_models: Ensures a ValueError if n_top_models exceeds the number of available models for the specified task.
    • Unrecognized priority_tuners: Verifies a ValueError for unrecognized tuner names.
    • Inappropriate refit_metric: Checks for a ValueError if refit_metric is not suitable for the given task_type.
  3. Functionality tests: ... *

Example Test Code

Here's an example of testing invalid x_train type:

def test_model_tuning_core_invalid_x_train_type(sample_data_mrc_mtc):
    """
    Tests if model_tuning_core raises TypeError when 'x_train' is not a DataFrame or ndarray.
    """
    _, y_train_classification, _ = sample_data_mrc_mtc
    with pytest.raises(TypeError):
        model_tuning_core(x_train="invalid_type", y_train=y_train_classification, task_type='classification', models={'model': LogisticRegression()})

This test ensures that the function properly checks x_train's data type and raises an appropriate error if it's not a DataFrame or ndarray.

Access the Full Test Suite*

For a comprehensive view of all tests, including their implementations and additional configurations, you can access the full test suite here.