Skip to content

Commit 96282b7

Browse files
committed
0.2.2
**Minor Improvements** - SearchEngine.by_zipcode has a new optional parameter ``zero_padding=True``. **Bugfixes** - SearchEngine.by_zipcode should returns any zipcode_type by default. (It used to only return standard zipcode)
1 parent 88ce441 commit 96282b7

6 files changed

Lines changed: 49 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ${shell pwd}/make/python_env.mk
1+
include ./make/python_env.mk

make/python_env.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Auto generated from pygitrepo 0.0.22
2+
# Auto generated from pygitrepo 0.0.24
33
#
44
# This Makefile is a dev-ops tool set.
55
# Compatible with:

release-history.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@ Release and Version History
44
==============================================================================
55

66

7-
0.2.2 (TODO)
7+
0.2.3 (TODO)
88
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
**Features and Improvements**
1010

11+
- Get lat lng and more geo info from Google Geocoding API for **Unique** and **PO Box** zipcode.
12+
1113
**Minor Improvements**
1214

1315
**Bugfixes**
1416

1517
**Miscellaneous**
1618

1719

20+
0.2.2 (2018-10-15)
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
**Minor Improvements**
24+
25+
- SearchEngine.by_zipcode has a new optional parameter ``zero_padding=True``.
26+
27+
**Bugfixes**
28+
29+
- SearchEngine.by_zipcode should returns any zipcode_type by default. (It used to only return standard zipcode)
30+
31+
1832
0.2.1 (2018-09-29)
1933
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2034
**Features and Improvements**

tests/search/test_census_data.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55
from base import TestSearchEngineBase
6-
from uszipcode.model import Zipcode
6+
from uszipcode.model import Zipcode, ZipcodeType
77

88

99
class TestSearchEngineCensusData(TestSearchEngineBase):
@@ -15,6 +15,14 @@ def test(self):
1515
z.head_of_household_by_age
1616
z.polygon
1717

18+
def test_by_zipcode_non_standard(self):
19+
"""
20+
Test by_zipcode should return any type zipcode.
21+
"""
22+
z = self.search.by_zipcode(48874)
23+
assert z.zipcode_type != ZipcodeType.Standard
24+
assert z.lat is not None
25+
1826

1927
if __name__ == "__main__":
2028
import os

uszipcode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except Exception as e: # pragma: no cover
1515
print(e)
1616

17-
__version__ = "0.2.1"
17+
__version__ = "0.2.2"
1818
__short_description__ = ("USA zipcode programmable database, includes "
1919
"up-to-date census and geometry information.")
2020
__license__ = "MIT"

uszipcode/search.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ def query(self,
333333
:param median_household_income_lower:
334334
:param median_household_income_upper:
335335
:param zipcode_type: str or :class`~uszipcode.model.ZipcodeType` attribute.
336+
if None, allows to return any type of zipcode.
337+
if specified, only return specified zipcode type.
336338
:param sort_by: str or :class:`~uszipcode.model.Zipcode` attribute,
337339
specified which field is used for sorting.
338340
:param ascending: bool, True means ascending, False means descending.
@@ -531,13 +533,30 @@ def query(self,
531533
else:
532534
return q.all()
533535

534-
def by_zipcode(self, zipcode):
536+
def by_zipcode(self,
537+
zipcode,
538+
zipcode_type=None,
539+
zero_padding=True):
535540
"""
536541
Search zipcode by exact 5 digits zipcode. No zero padding is needed.
542+
543+
:param zipcode: int or str, the zipcode will be automatically
544+
zero padding to 5 digits.
545+
:param zipcode_type: str or :class`~uszipcode.model.ZipcodeType` attribute.
546+
by default, it returns any zipcode type.
547+
:param zero_padding: bool, toggle on and off automatic zero padding.
537548
"""
538-
zipcode = str(zipcode).zfill(5)
549+
if zero_padding:
550+
zipcode = str(zipcode).zfill(5)
551+
else: # pragma: no cover
552+
zipcode = str(zipcode)
539553

540-
res = self.query(zipcode=zipcode, sort_by=None, returns=1)
554+
res = self.query(
555+
zipcode=zipcode,
556+
sort_by=None,
557+
returns=1,
558+
zipcode_type=zipcode_type,
559+
)
541560
if len(res):
542561
return res[0]
543562
else:

0 commit comments

Comments
 (0)