Add pathlib support in `save_dataset` (and elsewhere)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 335
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 10
Description
Feature Request
Is your feature request related to a problem? Please describe.
Scene.save_dataset accepts a path only as a string. It does not accept pathlib.Path objects.
Describe the solution you'd like
I would like that Scene.save_dataset accepts pathlib.Path objects.
Describe any changes to existing user workflow
There is no reasonable way in which adding this can break anybody's workflow.
Additional context
I'm not sure if this belong here or in trollsift. When attempting to write to a pathlib.Path object, the exception is actually coming from trollsift:
Traceback (most recent call last):
File "mwe30.py", line 7, in <module>
sc.save_dataset("tofu", Path("/tmp/tofu.png"))
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/satpy/scene.py", line 1301, in save_dataset
return writer.save_dataset(self[dataset_id],
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/satpy/writers/__init__.py", line 829, in save_dataset
return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/satpy/writers/simple_image.py", line 62, in save_image
filename = filename or self.get_filename(**img.data.attrs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/satpy/writers/__init__.py", line 658, in get_filename
output_filename = self.filename_parser.compose(kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/trollsift/parser.py", line 54, in compose
return compose(self.fmt, keyvals)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/trollsift/parser.py", line 409, in compose
return formatter.format(fmt, **keyvals)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/string.py", line 163, in format
return self.vformat(format_string, args, kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/string.py", line 167, in vformat
result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/string.py", line 177, in _vformat
self.parse(format_string):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/string.py", line 261, in parse
return _string.formatter_parser(format_string)
TypeError: expected str, got PosixPath
There may be other I/O functionality in satpy specifically and pytroll more generally where a path is currently accepted only as a string and not as a pathlib.Path object.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Scene.save_dataset and follow the traceback through satpy/writers/init.py, satpy/writers/simple_image.py, and the trollsift parser. Check the related I/O paths mentioned in the issue and establish coverage showing that pathlib.Path values are accepted wherever string paths are supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100