-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix rasterio chunking with s3 datasets #1817
Conversation
You can test this by mocking from unittest import mock # but note that we use a special import for mock in xarray
with mock.patch('os.path.getmtime', side_effect=RuntimeError):
os.path.getmtime('fooasdf.txt') |
xarray/backends/rasterio_.py
Outdated
try: | ||
mtime = os.path.getmtime(filename) | ||
except FileNotFoundError: | ||
# the filename is probably and s3 bucket rather than a regular file |
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.
and -> an
xarray/backends/rasterio_.py
Outdated
mtime = os.path.getmtime(filename) | ||
try: | ||
mtime = os.path.getmtime(filename) | ||
except FileNotFoundError: |
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.
Python 2 only has the super-class OSError
, so that should probably be used instead here.
I also refactored the rasterio test suite to eliminate a lot of boilerplate dataset creation and added tests for network urls. I'm not a geotiff expert, so please let me know if I have done anything silly. |
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.
def test_http_url(self): | ||
# more examples urls here | ||
# http://download.osgeo.org/geotiff/samples/ | ||
url = 'http://download.osgeo.org/geotiff/samples/made_up/ntf_nord.tif' |
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 forgot about the @network
decorator, this can be quite useful for other tests as well...
I probably should have paid more attention to those PR's. My apologies. Here is how I ended up refactoring the tests. I had to write a new test to catch the bug I discovered. I looked at the existing tests for guidance and saw lots of boilerplate. So rather than copying the boilerplate, I refactored it. Let me know how I can help resolve this conflicts this may cause with the other open PRs. |
#1740 is OK since the tests are still missing. My PR is a bit more problematic, but I can handle it. I would favor pushing yours forward now and I'll rebase my PR on top of it. |
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 great, thank you!
@rabernat this now has some conflicts to resolve. Can you fix those and merge this? Thanks! |
I resolved conflicts. LGTM before it gets stale again! Is it bad form to merge my own PR? |
@rabernat @fmaussion it's fine to merge your own PR once it's been reviewed & approved by another core developer. |
This looks good so let's get it in! |
@fmaussion - so sorry I accidentally deleted your tests. I was just rushing to resolve the conflicts so as not to hold up the other PRs. I hope this does not cause too much inconvenience. |
@rabernat no problem, will go back the rasterio tests soon |
git diff upstream/master **/*py | flake8 --diff
(remove if you did not edit any Python files)whats-new.rst
for all changes andapi.rst
for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)This is a simple fix for token generation of non-filename targets for rasterio.
The problem is that I have no idea how to test it without actually hitting s3 (which requires boto and aws credentials).