Skip to content

Commit 390c5c4

Browse files
authored
type vs. geom_type with shapely (#488)
* resolve #487 * f-string format * assert correction
1 parent fd8b9d8 commit 390c5c4

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 21.12b0
4-
hooks:
5-
- id: black
6-
language_version: python3.9
2+
- repo: https://github.com/psf/black
3+
rev: 22.10.0
4+
hooks:
5+
- id: black
6+
language_version: python3

libpysal/examples/tests/test_available.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,48 @@
55
import unittest
66
import pandas
77

8-
from .. import (available, get_url, load_example)
8+
from .. import available, get_url, load_example
99

1010
from ..base import get_data_home
1111

1212
os_name = platform.system()
1313

1414

1515
class Testexamples(unittest.TestCase):
16-
1716
def test_available(self):
1817
examples = available()
1918
self.assertEqual(type(examples), pandas.core.frame.DataFrame)
2019
self.assertEqual(examples.shape, (98, 3))
2120

22-
def test_data_home(self):
21+
def test_data_home(self):
2322
pth = get_data_home()
2423
head, tail = os.path.split(pth)
25-
self.assertEqual(tail, 'pysal')
26-
if os_name == 'Linux':
24+
self.assertEqual(tail, "pysal")
25+
if os_name == "Linux":
2726
heads = head.split("/")
28-
self.assertEqual(heads[1], 'home')
29-
self.assertEqual(heads[-1], 'share')
30-
self.assertEqual(heads[-2], '.local')
31-
elif os_name == 'Darwin':
27+
self.assertEqual(heads[1], "home")
28+
self.assertEqual(heads[-1], "share")
29+
self.assertEqual(heads[-2], ".local")
30+
elif os_name == "Darwin":
3231
heads = head.split("/")
33-
self.assertEqual(heads[1], 'Users')
34-
self.assertEqual(heads[-1], 'Application Support')
35-
self.assertEqual(heads[-2], 'Library')
36-
elif os_name == 'Windows':
32+
self.assertEqual(heads[1], "Users")
33+
self.assertEqual(heads[-1], "Application Support")
34+
self.assertEqual(heads[-2], "Library")
35+
elif os_name == "Windows":
3736
heads = head.split("\\")
38-
self.assertEqual(heads[1], 'Users')
39-
self.assertEqual(heads[-2], 'Local')
40-
self.assertEqual(heads[-3], 'AppData')
37+
self.assertEqual(heads[1], "Users")
38+
self.assertEqual(heads[-2], "Local")
39+
self.assertEqual(heads[-3], "AppData")
4140

4241
def test_get_url(self):
43-
self.assertEqual(get_url('10740'), None)
44-
url = 'https://geodacenter.github.io/data-and-lab//data/baltimore.zip'
45-
self.assertEqual(get_url('Baltimore'), url)
42+
self.assertEqual(get_url("10740"), None)
43+
url = "https://geodacenter.github.io/data-and-lab//data/baltimore.zip"
44+
self.assertEqual(get_url("Baltimore"), url)
4645

4746
def test_load_example(self):
4847
taz = load_example("taz")
4948
flist = taz.get_file_list()
50-
self.assertEquals(len(flist), 4)
49+
self.assertEqual(len(flist), 4)
5150

5251

5352
suite = unittest.TestLoader().loadTestsFromTestCase(Testexamples)

libpysal/weights/_contW_lists.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ def _get_boundary_points(shape):
2020
Recursively handle polygons vs. multipolygons to
2121
extract the boundary point set from each.
2222
"""
23-
if shape.type.lower() == "polygon":
23+
if shape.geom_type.lower() == "polygon":
2424
shape = shape.boundary
2525
return _get_boundary_points(shape)
26-
elif shape.type.lower() == "linestring":
26+
elif shape.geom_type.lower() == "linestring":
2727
return list(map(tuple, list(zip(*shape.coords.xy))))
28-
elif shape.type.lower() == "multilinestring":
28+
elif shape.geom_type.lower() == "multilinestring":
2929
return list(it.chain(*(list(zip(*shape.coords.xy)) for shape in shape.geoms)))
30-
elif shape.type.lower() == "multipolygon":
31-
return list(it.chain(*(_get_boundary_points(part.boundary) for part in shape.geoms)))
30+
elif shape.geom_type.lower() == "multipolygon":
31+
return list(
32+
it.chain(*(_get_boundary_points(part.boundary) for part in shape.geoms))
33+
)
3234
else:
3335
raise TypeError(
3436
"Input shape must be a Polygon, Multipolygon, LineString, "
35-
" or MultiLinestring and was "
36-
" instead: {}".format(shape.type)
37+
f" or MultiLinestring and was instead: {shape.type}"
3738
)
3839

3940

@@ -118,5 +119,5 @@ def jcontiguity(self):
118119
except:
119120
pass
120121
else:
121-
raise Exception("Weight type {} Not Understood!".format(self.wttype))
122+
raise Exception(f"Weight type {self.wttype} Not Understood!")
122123
self.w = w

0 commit comments

Comments
 (0)