Skip to content
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

Datasets: support os.PathLike #2273

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

adamjstewart
Copy link
Collaborator

As of #2173, all TorchGeo datasets now support both str and pathlib.Path paths. However, pathlib.Path is actually a subclass of os.PathLike, and PEP 519 says to use:

typing.Union[str, bytes, os.PathLike]

to type hint all paths (we skipped bytes because it was a nightmare). This PR expands our support to all of os.PathLike (although I don't know any subclasses other than pathlib.Path).

@pioneerHitesh was there a reason we chose pathlib.Path instead of os.PathLike?

@adamjstewart adamjstewart added this to the 0.6.1 milestone Sep 3, 2024
@github-actions github-actions bot added datasets Geospatial or benchmark datasets testing Continuous integration testing labels Sep 3, 2024

hits = self.index.intersection(tuple(query), objects=True)
filepaths = cast(list[Path], [hit.object for hit in hits])
filepaths = cast(list[str], [hit.object for hit in hits])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of #2270, we can reasonably expect hit.object to be a str by default.

@@ -42,7 +41,7 @@
)


Path: TypeAlias = str | pathlib.Path
Path: TypeAlias = str | os.PathLike[str]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change of interest

@pioneerHitesh
Copy link
Contributor

@adamjstewart To the best of my knowledge there wasn't any technical reason to choose pathlib.Path over os.PathLike .We implemented pathlib.Path support as it was mentioned in the original issue.

@adamjstewart adamjstewart merged commit 891f192 into microsoft:main Sep 10, 2024
19 checks passed
@adamjstewart adamjstewart deleted the datasets/pathlike branch September 10, 2024 15:27
adamjstewart added a commit that referenced this pull request Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets testing Continuous integration testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants