Skip to content

Commit

Permalink
Merge pull request #700 from davidhassell/https-fix
Browse files Browse the repository at this point in the history
Fix bug that prevented `https://` netCDF files from being read
  • Loading branch information
davidhassell authored Oct 9, 2023
2 parents 2cfc8e6 + b31291e commit 972cdaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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

0 comments on commit 972cdaa

Please sign in to comment.