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

Update search.py #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions uszipcode/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)),
Expand Down