-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
grass.jupyter: Support pathlib.Path in TimeSeriesMap.save #2453
grass.jupyter: Support pathlib.Path in TimeSeriesMap.save #2453
Conversation
wenzeslaus
commented
Jun 20, 2022
•
edited
Loading
edited
- API: TimeSeriesMap.save now supports pathlib.Path objects (and strings as before).
- tests: Use tmp_path, not current dir. Files generated by the tests should use tmp_path (or other pytest tmp dir ways), not the current directory.
36966dc
to
77b73c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Does writing to the current directory cause tests to fail?
I tried to figure out why the pytest check is failing (AttributeError: 'PosixPath' object has no attribute 'endswith'
) but I'm not sure.
77b73c9
to
50129b2
Compare
The code should actually support both string and Path objects, but it supported only strings, so the new text code broke it. This PR now fixes the code. Writing to the the current works (most of the time), but a file is left in that directory while using pytest tmp dir, the files are managed by pytest and in one place. (They are accessible after the test finishes and are deleted time to time.) |
50129b2
to
8042302
Compare
Files generated by the tests should use tmp_path (or other pytest tmp dir ways), not the current directory.
…e suffix (extension) instead of manipulating strings. PIL.Image supports Path for 8 years.
8042302
to
3ca1eb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand now. Thanks! Looks good to me.
When the save method receives a path, ensure the path is pathlib.Path, then use its functions to detect file suffix (extension) instead of manipulating strings. PIL.Image supports Path for 8 years, so we can support that and get the string support by conversion to Path. In tests, use tmp_path, not current dir. Files generated by the tests should use tmp_path (or other pytest tmp dir ways), not the current directory.
When the save method receives a path, ensure the path is pathlib.Path, then use its functions to detect file suffix (extension) instead of manipulating strings. PIL.Image supports Path for 8 years, so we can support that and get the string support by conversion to Path. In tests, use tmp_path, not current dir. Files generated by the tests should use tmp_path (or other pytest tmp dir ways), not the current directory.