Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes circular imports #1177

Merged
merged 1 commit into from
Apr 19, 2021
Merged

Fixes circular imports #1177

merged 1 commit into from
Apr 19, 2021

Conversation

ngupta23
Copy link
Collaborator

Related Issuse or bug

There were circular imports when ModelContainer and MetricsContainer were imported in the same file. Fixed this.
Also, cleaned up some unit tests for time_series

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Unit Tests are passing.

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

@ngupta23 ngupta23 changed the base branch from master to time_series April 19, 2021 12:20
@ngupta23 ngupta23 changed the title Fixxes circular imports Fixes circular imports Apr 19, 2021
exp = TimeSeriesExperiment()
for name, fh in model_parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that here when pytest collects the test it would not report the tests as separate

test_time_series.py::test_create_model[8-ARIMA]                   
test_time_series.py::test_create_model[6-Polynomial]
test_time_series.py::test_create_model[7-ETS]

maybe there's a way to yield the results from fixtures or passing the results from the fixture throught the argvalues argument of pytest.mark.parametrize.

Some references: here, here and here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TremaMiguel , Yes, it would be nice to convert it to a parameterized test. I will experiment more with it before the next PR. Thanks for the references.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like one can pass a function to pytest.mark.parametrize() , for example,

def model_parameters():

    globals_dict = {"seed": 0, "n_jobs_param": -1}
    model_containers = get_all_model_containers(globals_dict)

    model_names_ = []
    for model_name in model_containers.keys():
        if not model_name.startswith(("ensemble")):
            model_names_.append(model_name)

    parameters = [
        (name, np.arange(1, randint(6, 24)) if i%2==0  else randint(6, 24))
        for i, name in enumerate(model_names_)
    ]

    return parameters

this function can be called inside test_create_model

@pytest.mark.parametrize("model_parameter", model_parameters())
def test_create_model(load_setup, model_parameter, load_data):
    """test create_model functionality
    """
    exp = TimeSeriesExperiment()
    name, fh = model_parameter
    # Need to create individual setup for each model since the `fh` will be different for all models
    exp.setup(
        data=load_data, fold=3, fh=fh, fold_strategy="expandingwindow", verbose=False
    )
    model_obj = exp.create_model(name)

    y_pred = model_obj.predict()
    assert isinstance(y_pred, pd.Series)

    fh_index = fh if isinstance(fh, int) else fh[-1]
    expected_period_index = load_data.iloc[-fh_index:].index
    assert np.all(y_pred.index == expected_period_index)

will be adding this in my next PR.

@ngupta23
Copy link
Collaborator Author

I will merge this since @Yard1 already reviewed it in person.

@ngupta23 ngupta23 merged commit ba992b8 into time_series Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants