Skip to content

[BUG] Attempting to save a model without specifying a path throws an exception on Windows #1560

@JLC827

Description

@JLC827

Describe the bug
The model documentation states that when calling model.save the path parameter is optional, and that "If no path is specified, the model is automatically saved under "{ModelClass}_{YYYY-mm-dd_HH:MM:SS}.pt". E.g., "RNNModel_2020-01-01_12:00:00.pt".

However, if it is left unfilled the following exception will be thrown:

File "...\venv\lib\site-packages\darts\models\forecasting\torch_forecasting_model.py", line 1271, in save
    with open(path, "wb") as f_out:
OSError: [Errno 22] Invalid argument: 'RNNModel_2023-02-11_23:31:42.pt'

I assume this is because ':' cannot be used in file names in Windows. One possibility is to use the formatting of '%Y%m%d-%H%M%S' as specified in this Stack Overflow post.

To Reproduce
Simply run.

from darts.models import RNNModel

model = RNNModel(input_chunk_length=4)
model.save()

Expected behavior
It is expected for the model to save in the current working dir in a reasonable model name and date format.

System (please complete the following information):

  • Python version: 3.10
  • darts version 0.23.1
  • Windows 10.0.19045

Thanks!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions