Skip to content

Commit d77c853

Browse files
authored
fix(codes): name the Virgin Islands as the services do (#432)
codes.states named FIPS 78 "US Virgin Islands". Water Data and NGWMN both filter state_name on "Virgin Islands" and match exactly, so state="VI" returned no rows from either service: 0 rather than 1,092 monitoring locations, and 0 rather than 3 NGWMN sites. The Census name is still accepted as input. The territory tests are consolidated to one row per territory, each checking that its name, postal code, and FIPS code resolve to one another; the encodings themselves (case, US: prefix) are Test_to_state's.
1 parent ff905de commit d77c853

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎dataretrieval/codes/states.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"Guam": "gu",
7373
"Northern Mariana Islands": "mp",
7474
"Puerto Rico": "pr",
75-
"US Virgin Islands": "vi",
75+
"Virgin Islands": "vi",
7676
}
7777

7878
fips_codes = {
@@ -131,7 +131,7 @@
131131
"Guam": "66",
132132
"Northern Mariana Islands": "69",
133133
"Puerto Rico": "72",
134-
"US Virgin Islands": "78",
134+
"Virgin Islands": "78",
135135
}
136136

137137
# Reverse lookups (built once): postal code -> name, FIPS code -> name, and a
@@ -140,6 +140,9 @@
140140
_name_by_postal = {code: name for name, code in state_codes.items()}
141141
_name_by_fips = {fips: name for name, fips in fips_codes.items()}
142142
_name_by_lower = {name.lower(): name for name in state_codes}
143+
# The table names each state as the Water Data and NGWMN ``state_name`` fields
144+
# do. "US Virgin Islands" is the Census Bureau's name, accepted as input only.
145+
_name_by_lower["us virgin islands"] = "Virgin Islands"
143146

144147

145148
def to_state(

‎tests/utils_test.py‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -526,24 +526,31 @@ class TestTerritories:
526526
"""
527527

528528
@pytest.mark.parametrize(
529-
("value", "name", "postal", "fips"),
529+
("name", "postal", "fips"),
530530
[
531-
("Puerto Rico", "Puerto Rico", "PR", "72"),
532-
("PR", "Puerto Rico", "PR", "72"),
533-
("72", "Puerto Rico", "PR", "72"),
534-
("US:72", "Puerto Rico", "PR", "72"),
535-
("Guam", "Guam", "GU", "66"),
536-
("VI", "US Virgin Islands", "VI", "78"),
537-
("60", "American Samoa", "AS", "60"),
538-
("MP", "Northern Mariana Islands", "MP", "69"),
531+
("Puerto Rico", "PR", "72"),
532+
("Guam", "GU", "66"),
533+
("Virgin Islands", "VI", "78"),
534+
("American Samoa", "AS", "60"),
535+
("Northern Mariana Islands", "MP", "69"),
539536
],
540537
)
541-
def test_every_encoding_resolves(self, value, name, postal, fips):
538+
def test_each_territory_is_in_both_code_tables(self, name, postal, fips):
539+
"""Each code resolves to the others. The input encodings themselves are
540+
:class:`Test_to_state`'s concern."""
542541
from dataretrieval.codes.states import to_state
543542

544-
assert to_state(value, "name") == name
545-
assert to_state(value, "postal") == postal
546-
assert to_state(value, "fips") == fips
543+
for value in (name, postal, fips):
544+
assert to_state(value, "name") == name
545+
assert to_state(value, "postal") == postal
546+
assert to_state(value, "fips") == fips
547+
548+
def test_the_census_name_of_the_virgin_islands_is_accepted(self):
549+
"""The table names it as the services do; the name it had before is
550+
still accepted as input."""
551+
from dataretrieval.codes.states import to_state
552+
553+
assert to_state("US Virgin Islands") == "Virgin Islands"
547554

548555
def test_the_ngwmn_shim_routes_a_territory_to_each_queryable(self):
549556
"""``sites`` filters on ``state_name``, ``providers`` on ``state``."""

0 commit comments

Comments
 (0)