Skip to content

Fix 813 overwrite#934

Open
Vadim3377 wants to merge 5 commits intoneuroinformatics-unit:mainfrom
Vadim3377:fix-813-overwrite
Open

Fix 813 overwrite#934
Vadim3377 wants to merge 5 commits intoneuroinformatics-unit:mainfrom
Vadim3377:fix-813-overwrite

Conversation

@Vadim3377
Copy link
Copy Markdown

Description

What is this PR

Bug fix

Why is this PR needed?

Currently, attempting to save a file to a path that already exists raises a FileExistsError due to validation logic in validate_file_path. This makes it inconvenient to re-run code that writes outputs to the same file path, which is a common workflow in data analysis.

Most scientific Python libraries allow overwriting files when writing, so the current behaviour violates user expectations.

What does this PR do?

This PR modifies _file_is_writable in movement.validators.files to allow overwriting existing files.

Specifically:

  • Removes the check that raises FileExistsError when the file already exists
  • Keeps the check that ensures the parent directory is writable

This aligns the behaviour of validate_file_path(..., permission="w") with standard Python file writing semantics (e.g., open(..., "w")).

References

Fixes #813

How has this PR been tested?

  • Manually tested saving functions that rely on validate_file_path, including:

    • save_poses.to_dlc_file
    • save_bboxes.to_via_tracks_file
  • Verified that:

    • Saving to a new file works as before
    • Saving to an existing file no longer raises FileExistsError
    • Files are correctly overwritten

Is this a breaking change?

No.

This change relaxes existing validation behaviour and does not remove or modify any public API. Existing workflows that previously succeeded will continue to work, and workflows that previously failed due to file existence will now succeed.

Does this PR require an update to the documentation?

No.

The change aligns behaviour with typical expectations for file writing, and no documentation currently guarantees that existing files must not be overwritten.

@sonarqubecloud
Copy link
Copy Markdown

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.

Overwrite existing file when saving

1 participant