diff --git a/docs/conf.py b/docs/conf.py index 044dc0d49..e67cadd0a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,7 +59,7 @@ 'python': ('https://docs.python.org/3/', None), 'numpy': ('https://docs.scipy.org/doc/numpy/', None), 'matplotlib': ('https://matplotlib.org', None), - 'requests': ('https://2.python-requests.org/en/master/', None), + 'requests': ('https://requests.kennethreitz.org/en/master/', None), } # Add any paths that contain templates here, relative to this directory. diff --git a/examples/ndbc/buoy_met_request.py b/examples/ndbc/buoy_met_request.py index 1264ee21e..9b1303f06 100644 --- a/examples/ndbc/buoy_met_request.py +++ b/examples/ndbc/buoy_met_request.py @@ -16,7 +16,7 @@ #################################################### # Get a pandas data frame of all of the observations, meteorological data is the default # observation set to query. -df = NDBC.realtime_observations('41002') +df = NDBC.realtime_observations('46006') df.head() #################################################### diff --git a/siphon/catalog.py b/siphon/catalog.py index bc8273111..b4b1039d7 100644 --- a/siphon/catalog.py +++ b/siphon/catalog.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Siphon Contributors. +# Copyright (c) 2013-2019 Siphon Contributors. # Distributed under the terms of the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause """ @@ -11,6 +11,7 @@ from datetime import datetime import logging import re +import warnings import xml.etree.ElementTree as ET # noqa:N814 try: from urlparse import urljoin, urlparse @@ -146,6 +147,9 @@ def filter_time_range(self, start, end, regex=None, strptime=None): All values corresponding to times within the specified range """ + if start > end: + warnings.warn('The provided start time comes after the end time. No data will ' + 'be returned.', UserWarning) return [item[-1] for item in self._get_datasets_with_times(regex, strptime) if start <= item[0] <= end] diff --git a/siphon/http_util.py b/siphon/http_util.py index 525d58305..9633df7d5 100644 --- a/siphon/http_util.py +++ b/siphon/http_util.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2015 Siphon Contributors. +# Copyright (c) 2013-2019 Siphon Contributors. # Distributed under the terms of the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause """Utility code to support making requests using HTTP.""" @@ -8,6 +8,7 @@ from io import BytesIO from itertools import chain import posixpath +import warnings try: from urllib.parse import urlencode, urljoin # noqa except ImportError: @@ -317,6 +318,9 @@ def time_range(self, start, end): Returns self for chaining calls """ + if start > end: + warnings.warn('The provided start time comes after the end time. No data will ' + 'be returned.', UserWarning) self._set_query(self.time_query, time_start=self._format_time(start), time_end=self._format_time(end)) return self diff --git a/siphon/tests/test_catalog.py b/siphon/tests/test_catalog.py index 54f1ab2cd..98747070b 100644 --- a/siphon/tests/test_catalog.py +++ b/siphon/tests/test_catalog.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Siphon Contributors. +# Copyright (c) 2013-2019 Siphon Contributors. # Distributed under the terms of the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause """Test the catalog access API.""" @@ -232,6 +232,18 @@ def test_datasets_time_range(): 'NAM_CONUS_20km_noaaport_20150529_0000.grib1'] +@recorder.use_cassette('top_level_20km_rap_catalog') +def test_datasets_bad_time_range(): + """Test warning message for bad time range.""" + with pytest.warns(UserWarning): + url = ('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/NAM/' + 'CONUS_20km/noaaport/catalog.xml') + cat = TDSCatalog(url) + in_range = cat.catalog_refs.filter_time_range(datetime(2015, 5, 29, 0), + datetime(2015, 5, 28, 0)) + assert in_range == [] + + @recorder.use_cassette('top_level_20km_rap_catalog') def test_datasets_time_range_regex(): """Test getting datasets by time range using filenames, with manual regex.""" diff --git a/siphon/tests/test_http_util.py b/siphon/tests/test_http_util.py index 460d5ab04..579d37de4 100644 --- a/siphon/tests/test_http_util.py +++ b/siphon/tests/test_http_util.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2015 Siphon Contributors. +# Copyright (c) 2013-2019 Siphon Contributors. # Distributed under the terms of the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause """Test Siphon's base HTTP helper functionality.""" @@ -102,6 +102,14 @@ def test_data_query_time_format(): assert query == 'time=2015-06-15T12%3A00%3A00' +def test_data_query_bad_time_range(): + """Test that time queries are properly formatted.""" + with pytest.warns(UserWarning): + dt = datetime(2015, 6, 15, 12, 0, 0) + dt2 = datetime(2015, 6, 14, 12, 0, 0) + DataQuery().time_range(dt, dt2) + + def test_data_query_spatial_reset(): """Test that spatial queries reset each other.""" dr = DataQuery().lonlat_box(1, 2, 3, 4).lonlat_point(-1, -2)