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

Add support for PathLike objects to model save() and load() #1754

Merged
merged 10 commits into from
May 21, 2023

Conversation

sudrich
Copy link
Contributor

@sudrich sudrich commented May 10, 2023

Fixes #1751.

Summary

Added support for PathLike objects to the save() and load() functions of ForecastingModel.
This is achieved by explicitly including os.PathLike as a possible input for the path.
In addition, a check was added that raises a ValueError for invalid input arguments.

Other Information

@sudrich sudrich force-pushed the feature/add_pathlike_support branch from a441c0e to 3db5c9c Compare May 10, 2023 09:18
@madtoinou
Copy link
Collaborator

As mentioned in the associated issue, this is a duplicate of #1716.

While scrolling through the changes, I noticed that the new lines in the changelog are not in the right section; you edited the release 0.24.0 instead of adding a new bullet point in the unreleased section. Can you please address this?

@sudrich
Copy link
Contributor Author

sudrich commented May 11, 2023

As mentioned in the associated issue, this is a duplicate of #1716.

While scrolling through the changes, I noticed that the new lines in the changelog are not in the right section; you edited the release 0.24.0 instead of adding a new bullet point in the unreleased section. Can you please address this?

My bad. Moved the entry to the correct section.

@codecov-commenter
Copy link

codecov-commenter commented May 15, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.12 ⚠️

Comparison is base (f067f27) 94.18% compared to head (73635ea) 94.06%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1754      +/-   ##
==========================================
- Coverage   94.18%   94.06%   -0.12%     
==========================================
  Files         125      125              
  Lines       11500    11491       -9     
==========================================
- Hits        10831    10809      -22     
- Misses        669      682      +13     
Impacted Files Coverage Δ
darts/models/forecasting/forecasting_model.py 95.18% <100.00%> (+0.23%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

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

Thanks @sudrich, looks great 🚀

My only suggestion is to extend the test whether an error is raised for invalid paths (now that it should raise an error).

@@ -154,8 +155,9 @@ def test_save_load_model(self):

for model in [ARIMA(1, 1, 1), LinearRegressionModel(lags=12)]:
model_path_str = type(model).__name__
model_path_file = model_path_str + "_file"
model_paths = [model_path_str, model_path_file]
model_path_pathlike = pathlib.Path(model_path_str + "_pathlike")
Copy link
Collaborator

Choose a reason for hiding this comment

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

extending this test for invalid read/write path would be nice as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I put it in an extra test though to avoid inflating the original test too much.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

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

Looks good, just had one suggestion for using pytest over unit test.
Could you fix the current linting issues as well?

Comment on lines 215 to 219
# test save
self.assertRaises(ValueError, model.save, model_path_invalid)

# test load
self.assertRaises(ValueError, type(model).load, model_path_invalid)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# test save
self.assertRaises(ValueError, model.save, model_path_invalid)
# test load
self.assertRaises(ValueError, type(model).load, model_path_invalid)
# test save
with pytest.raises(ValueError):
model.save(model_path_invalid)
# test load
with pytest.raises(ValueError):
ARIMA.load(model_path_invalid)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

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

LGTM, thanks 🚀

@dennisbader dennisbader merged commit 1efb1f8 into unit8co:master May 21, 2023
alexcolpitts96 pushed a commit to alexcolpitts96/darts that referenced this pull request May 31, 2023
…1754)

* Add support for PathLike to model save/load

* Add entry to changelog

* Use bufferedIO classes instead of BinaryIO for class check

* Use raise_log for ValueErrors

* Move entry to correct section of changelog

* Add test for invalid inputs to save/load

* Use pytest for checking ValueError

---------

Co-authored-by: Dennis Bader <dennis.bader@gmx.ch>
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.

[FEATURE] Add suport for PathLike objects
4 participants