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

Fix bug that prevented https:// netCDF files from being read #700

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version 3.15.4
--------------

**2023-??-??**
**2023-10-??**

* Record dimension coordinate cell characteristics
(https://github.com/NCAS-CMS/cf-python/issues/692)
Expand All @@ -10,6 +10,10 @@ version 3.15.4
1-d constructs whose axis is not in the data, even when the
criterion was not matched
(https://github.com/NCAS-CMS/cf-python/issues/691)
* Fix bug that prevented "https://" netCDF files from being read
(https://github.com/NCAS-CMS/cf-python/issues/699)

----

version 3.15.3
--------------
Expand Down
4 changes: 3 additions & 1 deletion cf/read_write/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from numbers import Integral
from os.path import isdir
from re import Pattern
from urllib.parse import urlparse

from cfdm import is_log_level_info
from numpy.ma.core import MaskError
Expand Down Expand Up @@ -883,7 +884,8 @@ def read(
# Expand variables
file_glob = os.path.expanduser(os.path.expandvars(file_glob))

if file_glob.startswith("http://"):
scheme = urlparse(file_glob).scheme
if scheme in ("https", "http"):
# Do not glob a URL
files2 = (file_glob,)
else:
Expand Down
8 changes: 8 additions & 0 deletions cf/test/test_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,14 @@ def test_write_omit_data(self):
self.assertFalse(g.array.count())
self.assertTrue(g.construct("grid_latitude").array.count())

def test_read_url(self):
"""Test reading urls."""
for scheme in ("http", "https"):
remote = f"{scheme}://psl.noaa.gov/thredds/dodsC/Datasets/cru/crutem5/Monthlies/air.mon.anom.nobs.nc"
# Check that cf can access it
f = cf.read(remote)
self.assertEqual(len(f), 1)


if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
Expand Down