Skip to content

Commit

Permalink
Cut/v3.1.1 (unitedstates#70)
Browse files Browse the repository at this point in the history
* Linting fixes
* remove duplicate test test_dc()
* update packages
* update gh workflow
* update documentation
* fix version numbers

---------

Co-authored-by: Paul Hawk <[email protected]>
  • Loading branch information
pauldhawk and Paul Hawk authored May 30, 2023
1 parent 442364c commit 34da8f6
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9, "3.10", 3.11]

steps:
- uses: actions/checkout@v1
Expand Down
8 changes: 4 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==19.10b0"
black = "*"
flake8 = "*"
importlib_metadata = {version = "*", markers = "python_version < '3.8'"}
importlib_metadata = "*"
pytest = "*"
pytz = "*"
requests = "<3.0"

[packages]
jellyfish = "==0.7.2"
jellyfish = "==0.11.2"


[pipenv]
allow_prereleases = true
allow_prereleases = true
415 changes: 252 additions & 163 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ commits to the repo. To run these tests yourself: ::
Changelog
---------

3.1.1
~~~~~
* add support for Python 3.11
* upgrade to jellyfish 0.11.2


3.0.0
~~~~~

Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="us",
version="3.0.0",
version="3.1.1",
author="Jeremy Carbaugh",
author_email="[email protected]",
url="https://github.com/unitedstates/python-us",
Expand All @@ -13,12 +13,15 @@
license="BSD",
packages=find_packages(),
include_package_data=True,
install_requires=["jellyfish==0.7.2"],
install_requires=["jellyfish==0.11.2"],
entry_points={"console_scripts": ["states = us.cli.states:main"]},
platforms=["any"],
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
)
16 changes: 8 additions & 8 deletions us/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .states import (
STATES,
STATES_CONTIGUOUS,
STATES_CONTINENTAL,
TERRITORIES,
STATES_AND_TERRITORIES,
OBSOLETE,
)
from .states import ( # noqa
STATES, # noqa
STATES_CONTIGUOUS, # noqa
STATES_CONTINENTAL, # noqa
TERRITORIES, # noqa
STATES_AND_TERRITORIES, # noqa
OBSOLETE, # noqa
) # noqa
from .unitedstatesofamerica import * # noqa
3 changes: 0 additions & 3 deletions us/cli/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


def main():

import argparse

parser = argparse.ArgumentParser(description="Lookup state information")
Expand All @@ -19,7 +18,6 @@ def main():
sys.stdout.write("Sorry, couldn't find a matching state.\n")

else:

data = state.__dict__.copy()

region = "territory" if data.pop("is_territory") else "state"
Expand All @@ -36,7 +34,6 @@ def main():
sys.stdout.write(" other attributes:\n")

for key in sorted(data.keys()):

val = data[key]

if isinstance(val, (list, tuple)):
Expand Down
34 changes: 16 additions & 18 deletions us/states.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import itertools
import os
import re
from typing import Any, Dict, Iterable, List, Optional, Union
from typing import Any, Dict, Iterable, List, Optional
from urllib.parse import urljoin

import jellyfish # type: ignore
Expand All @@ -16,7 +15,6 @@


class State:

abbr: str
ap_abbr: Optional[str]
capital: Optional[str]
Expand All @@ -42,16 +40,16 @@ def __str__(self) -> str:
return self.name

def shapefile_urls(self) -> Optional[Dict[str, str]]:
""" Shapefiles are available directly from the US Census Bureau:
https://www.census.gov/cgi-bin/geo/shapefiles/index.php
"""Shapefiles are available directly from the US Census Bureau:
https://www.census.gov/cgi-bin/geo/shapefiles/index.php
"""

fips = self.fips

if not fips:
return None

base = f"https://www2.census.gov/geo/tiger/TIGER2010/"
base = "https://www2.census.gov/geo/tiger/TIGER2010/"
urls = {
"tract": urljoin(base, f"TRACT/2010/tl_2010_{fips}_tract10.zip"),
"cd": urljoin(base, f"CD/111/tl_2010_{fips}_cd111.zip"),
Expand All @@ -66,22 +64,22 @@ def shapefile_urls(self) -> Optional[Dict[str, str]]:


def lookup(val, field: Optional[str] = None, use_cache: bool = True) -> Optional[State]:
""" Semi-fuzzy state lookup. This method will make a best effort
attempt at finding the state based on the lookup value provided.
"""Semi-fuzzy state lookup. This method will make a best effort
attempt at finding the state based on the lookup value provided.
* two digits will search for FIPS code
* two letters will search for state abbreviation
* anything else will try to match the metaphone of state names
* two digits will search for FIPS code
* two letters will search for state abbreviation
* anything else will try to match the metaphone of state names
Metaphone is used to allow for incorrect, but phonetically accurate,
spelling of state names.
Metaphone is used to allow for incorrect, but phonetically accurate,
spelling of state names.
Exact matches can be done on any attribute on State objects by passing
the `field` argument. This skips the fuzzy-ish matching and does an
exact, case-sensitive comparison against the specified field.
Exact matches can be done on any attribute on State objects by passing
the `field` argument. This skips the fuzzy-ish matching and does an
exact, case-sensitive comparison against the specified field.
This method caches non-None results, but can the cache can be bypassed
with the `use_cache=False` argument.
This method caches non-None results, but can the cache can be bypassed
with the `use_cache=False` argument.
"""

matched_state = None
Expand Down
7 changes: 0 additions & 7 deletions us/tests/test_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ def test_wayoming():

def test_dc():
assert us.states.DC not in us.STATES
assert us.states.lookup("DC") == us.states.DC
assert us.states.lookup("District of Columbia") == us.states.DC
assert "DC" in us.states.mapping("abbr", "name")


# shapefiles
Expand Down Expand Up @@ -160,7 +157,3 @@ def test_contiguous():
def test_continental():
# Lower 48 + Alaska
assert len(us.STATES_CONTINENTAL) == 49


def test_dc():
assert us.states.DC not in us.STATES

0 comments on commit 34da8f6

Please sign in to comment.