From 417d25e8edf138817fcff5579b899bfd2f300938 Mon Sep 17 00:00:00 2001 From: RGAlexander216 <20406603+RGAlexander216@users.noreply.github.com> Date: Sun, 26 Feb 2023 12:51:56 -0600 Subject: [PATCH] Update search.py (final revision) Added the ability to specify the simple_or_comprehensive as an explicit string as well as a SearchEngine.SimpleOrComprehensiveEnum object Added type conversion for the lat, lng, and radius parameters in the SearchEngine class' query method with descriptive error handling --- uszipcode/search.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/uszipcode/search.py b/uszipcode/search.py index 3a94e90b14..3af549496f 100644 --- a/uszipcode/search.py +++ b/uszipcode/search.py @@ -136,11 +136,17 @@ def __init__( download_url: typing.Union[str, None] = None, engine: Engine = None, ): + if simple_or_comprehensive == 'simple': + simple_or_comprehensive = self.SimpleOrComprehensiveArgEnum.simple + if simple_or_comprehensive == 'comprehensive': + simple_or_comprehensive = self.SimpleOrComprehensiveArgEnum.comprehensive + validate_enum_arg( self.SimpleOrComprehensiveArgEnum, "simple_or_comprehensive", simple_or_comprehensive, ) + self.simple_or_comprehensive = simple_or_comprehensive if isinstance(engine, Engine): @@ -483,6 +489,23 @@ def query( """ filters = list() + if isinstance(lat, str) or isinstance(lng, str): + try: + lat = float(lat) + lng = float(lng) + except ValueError: + msg = ("Both values of lat ({}) and lng ({}) " + "must be int-like or float-like".format(lat, lng)) + raise ValueError(msg) + + if isinstance(radius, str): + try: + radius = float(radius) + except ValueError: + msg = ("The value of radius ({}) is not a valid " + "int-like or float-like string".format(radius)) + raise ValueError(msg) + # by coordinates _n_radius_param_not_null = sum([ isinstance(lat, (int, float)),