66from ... import examples
77from ..util import lat2W
88from ...common import RTOL , ATOL
9- from ... import io
10- from ...examples import get_path
9+
1110
1211try :
1312 import pandas
2019class Test_Adjlist (ut .TestCase ):
2120 def setUp (self ):
2221 self .knownW = io .open (examples .get_path ('columbus.gal' )).read ()
23-
22+
2423 def test_round_trip (self ):
2524 adjlist = self .knownW .to_adjlist (remove_symmetric = False ).astype (int )
2625 w_from_adj = weights .W .from_adjlist (adjlist )
27- np .testing .assert_allclose (w_from_adj .sparse .toarray (),
26+ np .testing .assert_allclose (w_from_adj .sparse .toarray (),
2827 self .knownW .sparse .toarray ())
2928
3029 def test_filter (self ):
@@ -33,7 +32,7 @@ def test_filter(self):
3332 assert len (alist ) == 4
3433 with self .assertRaises (AssertionError ):
3534 badgrid = weights .W .from_adjlist (alist )
36- np .testing .assert_allclose (badgrid .sparse .toarray (),
35+ np .testing .assert_allclose (badgrid .sparse .toarray (),
3736 grid .sparse .toarray ())
3837 assert set (alist .focal .unique ().tolist ()) == set (list (range (4 )))
3938 assert set (alist .neighbor .unique ().tolist ()) == set (list (range (4 )))
@@ -43,7 +42,7 @@ def test_filter(self):
4342 assert len (alist ) == 4
4443 with self .assertRaises (AssertionError ):
4544 badgrid = weights .W .from_adjlist (alist )
46- np .testing .assert_allclose (badgrid .sparse .toarray (),
45+ np .testing .assert_allclose (badgrid .sparse .toarray (),
4746 grid .sparse .toarray ())
4847 print (alist )
4948 tuples = set ([tuple (t ) for t in alist [['focal' ,'neighbor' ]].values ])
@@ -56,7 +55,7 @@ def test_filter(self):
5655 assert reversed_complements == tuples , ('the remaining links in the duplicated'
5756 ' adjlist are not the reverse of the links'
5857 ' in the deduplicated adjlist.' )
59- assert alist .weight .unique ().item () == 1
58+ assert alist .weight .unique ().item () == 1
6059
6160
6261 def apply_and_compare_columbus (self , col ):
@@ -66,7 +65,7 @@ def apply_and_compare_columbus(self, col):
6665 alist = adj .adjlist_apply (df [col ], W = W )
6766 right_hovals = alist .groupby ('focal' ).att_focal .unique ()
6867 assert (right_hovals == df [col ]).all ()
69- allpairs = np .subtract .outer (df [col ], df [col ])
68+ allpairs = np .subtract .outer (df [col ]. values , df [col ]. values )
7069 flat_diffs = allpairs [W .sparse .toarray ().astype (bool )]
7170 np .testing .assert_allclose (flat_diffs , alist ['subtract' ].values )
7271 return flat_diffs
@@ -80,7 +79,7 @@ def test_mvapply(self):
8079 W = weights .Queen .from_dataframe (df )
8180 ssq = lambda x_y : np .sum ((x_y [0 ]- x_y [1 ])** 2 ).item ()
8281 ssq .__name__ = 'sum_of_squares'
83- alist = adj .adjlist_apply (df [['HOVAL' , 'CRIME' , 'INC' ]], W = W ,
82+ alist = adj .adjlist_apply (df [['HOVAL' , 'CRIME' , 'INC' ]], W = W ,
8483 func = ssq )
8584 known_ssq = [1301.1639302990804 ,
8685 3163.46450914361 ,
@@ -101,11 +100,11 @@ def test_mvapply(self):
101100 rtol = RTOL , atol = ATOL )
102101
103102 def test_map (self ):
104- atts = ['HOVAL' , 'CRIME' , 'INC' ]
103+ atts = ['HOVAL' , 'CRIME' , 'INC' ]
105104 df = geopandas .read_file (examples .get_path ('columbus.dbf' )).head ()
106105 W = weights .Queen .from_dataframe (df )
107- hoval , crime , inc = list (map (self .apply_and_compare_columbus , atts ))
106+ hoval , crime , inc = list (map (self .apply_and_compare_columbus , atts ))
108107 mapped = adj .adjlist_map (df [atts ], W = W )
109108 for name ,data in zip (atts , (hoval , crime , inc )):
110- np .testing .assert_allclose (data ,
109+ np .testing .assert_allclose (data ,
111110 mapped ['_' .join (('subtract' ,name ))].values )
0 commit comments