diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f4ef42d5..f2376193a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: quarterly repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.5.7" + rev: "v0.6.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f59a9c1..053a2e827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this library are documented in this file. - Discontinue persisting text product into {mcd,mpd} table storage. - Discontinue storage of text product into sigmets, use `product_id` instead. +- Raise `IncompleteWebRequest` exception when autoplot datetime parsing fails. ### New Features diff --git a/src/pyiem/util.py b/src/pyiem/util.py index b9cd6413c..6d73ba514 100644 --- a/src/pyiem/util.py +++ b/src/pyiem/util.py @@ -53,6 +53,18 @@ def format(self, record): ) +def _strptime(ins: str, fmt: str, rectify: bool = False) -> datetime: + """Wrapper around strptime.""" + try: + return datetime.strptime(ins, fmt) + except ValueError as exp: + if rectify: + return handle_date_err(exp, ins, fmt) + raise IncompleteWebRequest( + f"String provided: `{ins}` does not match format: `{fmt}`" + ) from exp + + def web2ldm(url, ldm_product_name, md5_from_name=False, pqinsert="pqinsert"): """Download a URL and insert into LDM. @@ -321,7 +333,8 @@ def handle_date_err(exp, value, fmt): res = lastday.strftime("%Y-%m-%d") if len(tokens) > 1: res += " " + tokens[1] - return datetime.strptime(res, fmt) + # Careful here, we don't want a recursive loop + return _strptime(res, fmt, rectify=False) def get_autoplot_context(fdict, cfg, enforce_optional=False, **kwargs): @@ -442,11 +455,11 @@ def _float(val): elif typ == "datetime": # tricky here, php has YYYY/mm/dd and CGI has YYYY-mm-dd if default is not None: - default = datetime.strptime(default, "%Y/%m/%d %H%M") + default = _strptime(default, "%Y/%m/%d %H%M") if minval is not None: - minval = datetime.strptime(minval, "%Y/%m/%d %H%M") + minval = _strptime(minval, "%Y/%m/%d %H%M") if maxval is not None: - maxval = datetime.strptime(maxval, "%Y/%m/%d %H%M") + maxval = _strptime(maxval, "%Y/%m/%d %H%M") if value is not None: # A common problem is for the space to be missing if value.find(" ") == -1: @@ -455,50 +468,40 @@ def _float(val): else: value += " 0000" _dtfmt = "%Y-%m-%d %H%M" - try: - value = datetime.strptime( - value[:15].replace("/", "-"), "%Y-%m-%d %H%M" - ) - except ValueError as exp: - if kwargs.get("rectify_dates", False): - value = handle_date_err(exp, value, _dtfmt) - else: - # If we are not rectifying dates, we just raise the - # exception - raise + value = _strptime( + value[:15].replace("/", "-"), + "%Y-%m-%d %H%M", + rectify=kwargs.get("rectify_dates", False), + ) elif typ == "sday": # supports legacy uris with yyyy-mm-dd, before migration to sday if default is not None: - default = datetime.strptime(f"2000{default}", "%Y%m%d").date() + default = _strptime(f"2000{default}", "%Y%m%d").date() if minval is not None: - minval = datetime.strptime(f"2000{minval}", "%Y%m%d").date() + minval = _strptime(f"2000{minval}", "%Y%m%d").date() if maxval is not None: - maxval = datetime.strptime(f"2000{maxval}", "%Y%m%d").date() + maxval = _strptime(f"2000{maxval}", "%Y%m%d").date() if value is not None: if value.find("-") > -1: - value = datetime.strptime(value, "%Y-%m-%d").date() + value = _strptime(value, "%Y-%m-%d").date() else: - value = datetime.strptime(f"2000{value}", "%Y%m%d").date() + value = _strptime(f"2000{value}", "%Y%m%d").date() elif typ == "date": # tricky here, php has YYYY/mm/dd and CGI has YYYY-mm-dd if default is not None: - default = datetime.strptime(default, "%Y/%m/%d").date() + default = _strptime(default, "%Y/%m/%d").date() if minval is not None: - minval = datetime.strptime(minval, "%Y/%m/%d").date() + minval = _strptime(minval, "%Y/%m/%d").date() if maxval is not None: - maxval = datetime.strptime(maxval, "%Y/%m/%d").date() + maxval = _strptime(maxval, "%Y/%m/%d").date() if value is not None: - try: - value = datetime.strptime(value, "%Y-%m-%d").date() - except ValueError as exp: - if kwargs.get("rectify_dates", False): - value = handle_date_err(exp, value, "%Y-%m-%d").date() - else: - # If we are not rectifying dates, we just raise the - # exception - raise + value = _strptime( + value, + "%Y-%m-%d", + rectify=kwargs.get("rectify_dates", False), + ).date() elif typ == "vtec_ps": # VTEC phenomena and significance defaults = {} diff --git a/src/pyiem/webutil.py b/src/pyiem/webutil.py index 53647ba8d..364161aae 100644 --- a/src/pyiem/webutil.py +++ b/src/pyiem/webutil.py @@ -1,6 +1,5 @@ """Utility functions for iemwebfarm applications.""" -import datetime import random import re import string @@ -8,6 +7,7 @@ import traceback import warnings from collections import namedtuple +from datetime import datetime from http import HTTPStatus from zoneinfo import ZoneInfo, ZoneInfoNotFoundError @@ -237,7 +237,7 @@ def compute_ts_from_string(form, key): fmt += ".%f" if len(tstr.split(":")) == 2: fmt = "%Y-%m-%d %H:%M" - return datetime.datetime.strptime(tstr, fmt).replace(tzinfo=tz) + return datetime.strptime(tstr, fmt).replace(tzinfo=tz) def compute_ts(form, suffix): @@ -260,7 +260,7 @@ def compute_ts(form, suffix): else: day = 28 - return datetime.datetime( + return datetime( int(yearval), month, day, @@ -447,7 +447,7 @@ def _handle_exp(errormsg, routine=False, code=500): ) return [msg.encode("ascii")] - start_time = datetime.datetime.utcnow() + start_time = datetime.utcnow() status_code = 500 try: # mixed convers this to a regular dict @@ -489,7 +489,7 @@ def _handle_exp(errormsg, routine=False, code=500): ) except Exception: res = _handle_exp(traceback.format_exc()) - end_time = datetime.datetime.utcnow() + end_time = datetime.utcnow() if kwargs.get("enable_telemetry", True): write_telemetry( TELEMETRY( diff --git a/tests/grid/test_zs.py b/tests/grid/test_zs.py index e04577d8f..5d98c6c24 100644 --- a/tests/grid/test_zs.py +++ b/tests/grid/test_zs.py @@ -3,9 +3,10 @@ import numpy as np from affine import Affine from geopandas import GeoSeries -from pyiem.grid import zs from shapely.geometry import Polygon +from pyiem.grid import zs + def test_polygon_to_left(): """Test that we don't get an artifact in the first column.""" diff --git a/tests/models/test_models_shef.py b/tests/models/test_models_shef.py index 1d73d3430..7a8c03ac5 100644 --- a/tests/models/test_models_shef.py +++ b/tests/models/test_models_shef.py @@ -2,6 +2,7 @@ # pylint: disable=redefined-outer-name import pytest + from pyiem.models.shef import SHEFElement from pyiem.util import utc diff --git a/tests/ncei/test_ds3505.py b/tests/ncei/test_ds3505.py index fbaa68e37..c666538c1 100644 --- a/tests/ncei/test_ds3505.py +++ b/tests/ncei/test_ds3505.py @@ -2,6 +2,7 @@ # pylint: disable=redefined-outer-name import numpy as np + from pyiem.ncei import ds3505 from pyiem.util import get_test_filepath, utc diff --git a/tests/nws/products/test_cf6.py b/tests/nws/products/test_cf6.py index 2018b4da8..98e644209 100644 --- a/tests/nws/products/test_cf6.py +++ b/tests/nws/products/test_cf6.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products.cf6 import parser from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_cli.py b/tests/nws/products/test_cli.py index 73b769de5..d698a4152 100644 --- a/tests/nws/products/test_cli.py +++ b/tests/nws/products/test_cli.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products import cli from pyiem.nws.products import parser as cliparser from pyiem.nws.products.cli import CLIException, get_number diff --git a/tests/nws/products/test_cwa.py b/tests/nws/products/test_cwa.py index d72a4e83e..919de1e03 100644 --- a/tests/nws/products/test_cwa.py +++ b/tests/nws/products/test_cwa.py @@ -2,11 +2,11 @@ # third party import pytest +from shapely.geometry import Polygon # this from pyiem.nws.products.cwa import parser from pyiem.util import get_test_file, utc -from shapely.geometry import Polygon LOCS = { "AMG": {"lon": -82.51, "lat": 31.54}, diff --git a/tests/nws/products/test_dsm.py b/tests/nws/products/test_dsm.py index 418c392e3..cb74b32a2 100644 --- a/tests/nws/products/test_dsm.py +++ b/tests/nws/products/test_dsm.py @@ -4,6 +4,7 @@ from zoneinfo import ZoneInfo import pytest + from pyiem.nws.products.dsm import compute_time, parser, process from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_fd.py b/tests/nws/products/test_fd.py index 0e78a1bbb..c64d00046 100644 --- a/tests/nws/products/test_fd.py +++ b/tests/nws/products/test_fd.py @@ -1,6 +1,7 @@ """Test FD.""" import pytest + from pyiem.nws.products.fd import parse_encoding, parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_ffg.py b/tests/nws/products/test_ffg.py index 51667729d..9db39389c 100644 --- a/tests/nws/products/test_ffg.py +++ b/tests/nws/products/test_ffg.py @@ -1,6 +1,7 @@ """Testing FFG parsing.""" import pytest + from pyiem.nws.products.ffg import parser as ffgparser from pyiem.util import get_test_file diff --git a/tests/nws/products/test_hml.py b/tests/nws/products/test_hml.py index 8fdf85d7f..14b200a71 100644 --- a/tests/nws/products/test_hml.py +++ b/tests/nws/products/test_hml.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.nws.products.hml import parser as hmlparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_lsr.py b/tests/nws/products/test_lsr.py index 31200f147..92773f524 100644 --- a/tests/nws/products/test_lsr.py +++ b/tests/nws/products/test_lsr.py @@ -1,6 +1,7 @@ """Test Local Storm Report parsing.""" import pytest + from pyiem.nws.products.lsr import parse_lsr, parser from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file diff --git a/tests/nws/products/test_mcd.py b/tests/nws/products/test_mcd.py index 4bf53c0fa..68206ed75 100644 --- a/tests/nws/products/test_mcd.py +++ b/tests/nws/products/test_mcd.py @@ -1,6 +1,7 @@ """MCD/MPD tests.""" import pytest + from pyiem.exceptions import MCDException from pyiem.nws.products import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_metarcollect.py b/tests/nws/products/test_metarcollect.py index a3f026262..7237f4773 100644 --- a/tests/nws/products/test_metarcollect.py +++ b/tests/nws/products/test_metarcollect.py @@ -3,6 +3,7 @@ from unittest import mock import pytest + from pyiem.nws.products import metarcollect from pyiem.reference import TRACE_VALUE from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_mos.py b/tests/nws/products/test_mos.py index 5e24cd8bd..d9915ced4 100644 --- a/tests/nws/products/test_mos.py +++ b/tests/nws/products/test_mos.py @@ -1,6 +1,7 @@ """Test MOS Parsing.""" import pytest + from pyiem.nws.products.mos import parser as mosparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_nldn.py b/tests/nws/products/test_nldn.py index 36d9ad1ab..207d3da5d 100644 --- a/tests/nws/products/test_nldn.py +++ b/tests/nws/products/test_nldn.py @@ -1,6 +1,7 @@ """Test NLDN.""" import pytest + from pyiem.nws.products.nldn import parser from pyiem.util import get_test_filepath diff --git a/tests/nws/products/test_pirep.py b/tests/nws/products/test_pirep.py index b64f6406f..5342e2691 100644 --- a/tests/nws/products/test_pirep.py +++ b/tests/nws/products/test_pirep.py @@ -1,6 +1,7 @@ """PIREP.""" import pytest + from pyiem.nws.products.pirep import parser as pirepparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_products_vtec.py b/tests/nws/products/test_products_vtec.py index d56bfe952..45ca1f733 100644 --- a/tests/nws/products/test_products_vtec.py +++ b/tests/nws/products/test_products_vtec.py @@ -5,6 +5,7 @@ import pandas as pd import pytest + from pyiem.nws.nwsli import NWSLI from pyiem.nws.products.vtec import check_dup_ps from pyiem.nws.products.vtec import parser as _vtecparser diff --git a/tests/nws/products/test_saw.py b/tests/nws/products/test_saw.py index aaaea1c92..6d019143d 100644 --- a/tests/nws/products/test_saw.py +++ b/tests/nws/products/test_saw.py @@ -1,6 +1,7 @@ """Can we process the SAW""" import pytest + from pyiem.nws.products import parser from pyiem.nws.products.saw import parser as sawparser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_scp.py b/tests/nws/products/test_scp.py index f0c630ba4..71f58e20c 100644 --- a/tests/nws/products/test_scp.py +++ b/tests/nws/products/test_scp.py @@ -1,6 +1,7 @@ """Can we process the SCP""" import pytest + from pyiem.nws.products.scp import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/products/test_shef.py b/tests/nws/products/test_shef.py index 8b7efdd8b..b79ada3ae 100644 --- a/tests/nws/products/test_shef.py +++ b/tests/nws/products/test_shef.py @@ -6,6 +6,7 @@ import mock import pytest + from pyiem.exceptions import InvalidSHEFEncoding, InvalidSHEFValue from pyiem.nws.products.shef import ( make_date, diff --git a/tests/nws/products/test_spcpts.py b/tests/nws/products/test_spcpts.py index 01e2bedb0..ee4ff528b 100644 --- a/tests/nws/products/test_spcpts.py +++ b/tests/nws/products/test_spcpts.py @@ -1,6 +1,7 @@ """Unit Tests""" import pytest + from pyiem.nws.products import parser from pyiem.nws.products._outlook_util import debug_draw from pyiem.nws.products.spcpts import ( diff --git a/tests/nws/products/test_sps.py b/tests/nws/products/test_sps.py index 8d1983f9d..f7a3cc3f3 100644 --- a/tests/nws/products/test_sps.py +++ b/tests/nws/products/test_sps.py @@ -1,6 +1,7 @@ """SPS Parsing""" import pytest + from pyiem.nws.products import parser as spsparser from pyiem.nws.ugc import UGC from pyiem.reference import TWEET_CHARS diff --git a/tests/nws/products/test_taf.py b/tests/nws/products/test_taf.py index 8d508cb2f..e174d8faf 100644 --- a/tests/nws/products/test_taf.py +++ b/tests/nws/products/test_taf.py @@ -2,6 +2,7 @@ # Third Party import pytest + from pyiem.nws.products import parser as tafparser from pyiem.nws.products.taf import parser as real_tafparser from pyiem.reference import TAF_VIS_OVER_6SM diff --git a/tests/nws/test_bufkit.py b/tests/nws/test_bufkit.py index b6f474a3e..b7b58905b 100644 --- a/tests/nws/test_bufkit.py +++ b/tests/nws/test_bufkit.py @@ -5,6 +5,7 @@ # third party import pytest + from pyiem.nws.bufkit import read_bufkit # Local diff --git a/tests/nws/test_lsrclass.py b/tests/nws/test_lsrclass.py index 5e8bd52b5..ed2b391c6 100644 --- a/tests/nws/test_lsrclass.py +++ b/tests/nws/test_lsrclass.py @@ -1,6 +1,7 @@ """test lsr.""" import pytest + from pyiem.nws.lsr import _icestorm_remark as ir from pyiem.nws.products import lsr from pyiem.nws.products.lsr import _mylowercase diff --git a/tests/nws/test_product.py b/tests/nws/test_product.py index faed85c5b..4a6a58079 100644 --- a/tests/nws/test_product.py +++ b/tests/nws/test_product.py @@ -1,6 +1,7 @@ """Testing!""" import pytest + from pyiem.nws import product, ugc from pyiem.nws.product import ( TextProduct, diff --git a/tests/nws/test_products.py b/tests/nws/test_products.py index a416008f2..c274fe550 100644 --- a/tests/nws/test_products.py +++ b/tests/nws/test_products.py @@ -1,6 +1,7 @@ """Massive omnibus of testing for pyiem.nws.products.""" import pytest + from pyiem.exceptions import HWOException, TextProductException from pyiem.nws.products import parser from pyiem.util import get_test_file, utc diff --git a/tests/nws/test_ugc.py b/tests/nws/test_ugc.py index e858a03bd..fc80d7b6d 100644 --- a/tests/nws/test_ugc.py +++ b/tests/nws/test_ugc.py @@ -1,6 +1,7 @@ """Can we parse UGC strings""" import pytest + from pyiem.exceptions import UGCParseException from pyiem.nws import ugc from pyiem.util import utc diff --git a/tests/plot/test_calendarplot.py b/tests/plot/test_calendarplot.py index 4be68248d..615fb9f10 100644 --- a/tests/plot/test_calendarplot.py +++ b/tests/plot/test_calendarplot.py @@ -3,6 +3,7 @@ import datetime import pytest + from pyiem.plot.calendarplot import calendar_plot PAIN = 0.02 # how much do we care, sigh. diff --git a/tests/plot/test_geoplot.py b/tests/plot/test_geoplot.py index 0eeb5d428..d4eb6f6c7 100644 --- a/tests/plot/test_geoplot.py +++ b/tests/plot/test_geoplot.py @@ -10,6 +10,7 @@ import mock import numpy as np import pytest +from shapely.geometry import Polygon # Local from pyiem.dep import RAMPS @@ -25,7 +26,6 @@ from pyiem.plot.util import mask_outside_geom from pyiem.reference import LATLON, TWITTER_RESOLUTION_INCH from pyiem.util import load_geodf, utc -from shapely.geometry import Polygon # Increased threshold with matplotlib 3.6 tweaks PAIN = 4.1 diff --git a/tests/plot/test_layouts.py b/tests/plot/test_layouts.py index b9e04eaea..36e5088b0 100644 --- a/tests/plot/test_layouts.py +++ b/tests/plot/test_layouts.py @@ -2,6 +2,7 @@ # third party import pytest + from pyiem.plot.layouts import figure, figure_axes # local diff --git a/tests/plot/test_plot_utils.py b/tests/plot/test_plot_utils.py index 68512c41f..6aac9fe96 100644 --- a/tests/plot/test_plot_utils.py +++ b/tests/plot/test_plot_utils.py @@ -1,6 +1,7 @@ """Test pyiem.plot.utils.""" import pytest + from pyiem.plot.util import centered_bins, draw_logo, fitbox, pretty_bins diff --git a/tests/plot/test_windrose.py b/tests/plot/test_windrose.py index a7ea9e529..44e796cbf 100644 --- a/tests/plot/test_windrose.py +++ b/tests/plot/test_windrose.py @@ -3,6 +3,7 @@ import numpy as np import pytest from metpy.units import units + from pyiem.plot.colormaps import get_cmap from pyiem.plot.windrose import ( PLOT_CONVENTION_TO, diff --git a/tests/test_database.py b/tests/test_database.py index efdf73f97..cc4ad7f77 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -3,6 +3,7 @@ # third party import numpy as np import pytest + from pyiem import database from pyiem.exceptions import NewDatabaseConnectionFailure diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index 5f7f72f24..d66b13c2d 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -1,6 +1,7 @@ """Test our pyiem.datatypes hack.""" import pytest + from pyiem import datatypes diff --git a/tests/test_dep.py b/tests/test_dep.py index 047349e24..c84163345 100644 --- a/tests/test_dep.py +++ b/tests/test_dep.py @@ -4,6 +4,7 @@ import os import pytest + from pyiem import dep diff --git a/tests/test_geom_util.py b/tests/test_geom_util.py index 1c4d4db6a..629563e29 100644 --- a/tests/test_geom_util.py +++ b/tests/test_geom_util.py @@ -2,9 +2,10 @@ # Third Party # Local -from pyiem import geom_util from shapely.geometry import LineString, Polygon +from pyiem import geom_util + SQUARE = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) diff --git a/tests/test_iemre.py b/tests/test_iemre.py index d61376a15..7ac8a3c47 100644 --- a/tests/test_iemre.py +++ b/tests/test_iemre.py @@ -6,6 +6,7 @@ import numpy as np import pygrib from affine import Affine + from pyiem import database, iemre from pyiem.util import get_test_filepath, utc diff --git a/tests/test_meteorology.py b/tests/test_meteorology.py index 5a7604849..31d0e003d 100644 --- a/tests/test_meteorology.py +++ b/tests/test_meteorology.py @@ -5,6 +5,7 @@ import numpy as np import pytest from metpy.units import masked_array, units + from pyiem import datatypes, meteorology from pyiem.exceptions import InvalidArguments diff --git a/tests/test_mrms.py b/tests/test_mrms.py index c1b858bd0..34023eb9e 100644 --- a/tests/test_mrms.py +++ b/tests/test_mrms.py @@ -4,6 +4,7 @@ import os import requests + from pyiem import mrms from pyiem.util import utc diff --git a/tests/test_network.py b/tests/test_network.py index 83a05cb26..c49616dfc 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -4,6 +4,7 @@ from datetime import date import pytest + from pyiem import network diff --git a/tests/test_observation.py b/tests/test_observation.py index 1c3b24162..9b24cb684 100644 --- a/tests/test_observation.py +++ b/tests/test_observation.py @@ -9,6 +9,7 @@ import numpy as np import pandas as pd import pytest + from pyiem import observation from pyiem.database import get_dbconnc from pyiem.util import utc diff --git a/tests/test_tracker.py b/tests/test_tracker.py index b0da356eb..8e0d48826 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -4,6 +4,7 @@ from datetime import date, datetime, timedelta, timezone import pytest + from pyiem.database import get_dbconnc from pyiem.network import Table as NetworkTable from pyiem.tracker import TrackerEngine, loadqc diff --git a/tests/test_util.py b/tests/test_util.py index 4a6a6cd92..1dd2bb897 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -14,6 +14,7 @@ # third party import pytest + from pyiem import util from pyiem.exceptions import IncompleteWebRequest, UnknownStationException from pyiem.reference import ISO8601 @@ -331,12 +332,13 @@ def test_get_autoplot_context_dates(): } opts = dict( arguments=[ - dict( - type="date", - name="d", - default="2011/11/12", - maxval="2022/01/01", - ), + { + "type": "date", + "name": "d", + "default": "2011/11/12", + "max": "2022/01/01", + "min": "2011/01/01", + }, dict(type="datetime", name="d2", default="2011/11/12 1213"), {"type": "datetime", "name": "d3", "default": "2011/11/12 1213"}, ] @@ -346,21 +348,21 @@ def test_get_autoplot_context_dates(): assert ctx["d2"] == datetime(2016, 9, 30, 13, 14) assert ctx["d3"] == datetime(2016, 9, 30, 13, 14) form["d"] = "2016-06-30" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-XX" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-31" form["d2"] = "2016-09-30" # triggers appending 0000 - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) form["d"] = "2016-06-30" form["d2"] = "2016-09-30 2414" - with pytest.raises(ValueError): + with pytest.raises(IncompleteWebRequest): util.get_autoplot_context(form, opts, rectify_dates=False) diff --git a/tests/test_webutil.py b/tests/test_webutil.py index 53f2d479c..2493d0f51 100644 --- a/tests/test_webutil.py +++ b/tests/test_webutil.py @@ -8,6 +8,7 @@ import mock import pytest from pydantic import AwareDatetime, Field + from pyiem.database import get_dbconn from pyiem.exceptions import ( BadWebRequest, diff --git a/tests/test_wellknowntext.py b/tests/test_wellknowntext.py index 695f47d2a..a3a23443c 100644 --- a/tests/test_wellknowntext.py +++ b/tests/test_wellknowntext.py @@ -1,9 +1,10 @@ """tests""" import pytest -from pyiem import wellknowntext from shapely.geometry import LineString, Point, Polygon +from pyiem import wellknowntext + def test_bad_well_known_text(): """This should fail!""" diff --git a/tests/test_windrose_utils.py b/tests/test_windrose_utils.py index a1d613541..c55fe20c1 100644 --- a/tests/test_windrose_utils.py +++ b/tests/test_windrose_utils.py @@ -6,6 +6,7 @@ import pytest from metpy.units import units from pandas import read_csv + from pyiem.plot.windrose import PLOT_CONVENTION_TO from pyiem.util import utc from pyiem.windrose_utils import windrose diff --git a/util/create_transformed_parquet.py b/util/create_transformed_parquet.py index 696bf7dca..2e3a5b512 100644 --- a/util/create_transformed_parquet.py +++ b/util/create_transformed_parquet.py @@ -8,6 +8,7 @@ import click import geopandas as gpd + from pyiem.reference import EPSG from pyiem.util import logger diff --git a/util/make_bounds.py b/util/make_bounds.py index 8a9608d50..c2e6d59d9 100644 --- a/util/make_bounds.py +++ b/util/make_bounds.py @@ -1,11 +1,12 @@ """Generate the _ccw files used in pyIEM.""" import numpy as np -from pyiem.database import get_dbconn -from pyiem.plot.geoplot import MapPlot from shapely.geometry import MultiPolygon from shapely.wkb import loads +from pyiem.database import get_dbconn +from pyiem.plot.geoplot import MapPlot + def main(): """Go Main Go.""" diff --git a/util/make_cities.py b/util/make_cities.py index b92c69f04..7e8ab4218 100644 --- a/util/make_cities.py +++ b/util/make_cities.py @@ -3,6 +3,7 @@ """ from geopandas import read_parquet, read_postgis + from pyiem.database import get_dbconn FILENAME = "../src/pyiem/data/geodf/cities.parquet" diff --git a/util/make_ramps.py b/util/make_ramps.py index a8cd5a067..a172e6539 100644 --- a/util/make_ramps.py +++ b/util/make_ramps.py @@ -4,6 +4,7 @@ """ import pandas as pd + from pyiem.database import get_dbconnstr from pyiem.util import logger diff --git a/util/make_shapes.py b/util/make_shapes.py index 93a330b8e..50f5d321b 100644 --- a/util/make_shapes.py +++ b/util/make_shapes.py @@ -5,6 +5,7 @@ import warnings import geopandas as gpd + from pyiem.database import get_sqlalchemy_conn from pyiem.reference import state_bounds from pyiem.util import logger