nsidc / earthaccess

Python Library for NASA Earthdata APIs
https://earthaccess.readthedocs.io/
MIT License
372 stars 71 forks source link

`download` returns `Path` objects rather than strings when `in_region` #595

Open itcarroll opened 1 month ago

itcarroll commented 1 month ago

The download docs say that the return value shall be a list of strings. When running in_region however, the result is a list of pathlib.PosixPath objects.

import earthaccess
import pathlib

assert earthaccess.__version__ == "0.9.0"
assert earthaccess.__store__.in_region

local = pathlib.Path("data").mkdir(exist_ok=True)
results = earthaccess.search_data(short_name="PACE_OCI_L2_BGC_NRT", count=1)
paths = earthaccess.download(results, local_path=local)
assert isinstance(paths[0], str)

The last assert raises an exception.

mfisher87 commented 1 month ago

Nice catch! Why isn't our type checker catching this though?

https://github.com/nsidc/earthaccess/blob/9f43047f6d2f6845d33a9367814262b43d9bcc46/earthaccess/api.py#L177

I love pathlib though, should we update download() to always return Paths? :)

itcarroll commented 1 month ago

If you want to be fancy, you could return the same type given to you in the local_path argument.

andypbarrett commented 1 month ago

I like the idea of returning a list of Path objects. I think this would avoid cross platform issues.