Skip to content

Commit

Permalink
BUG: fix for deprecation removal of from_item in column tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsrey committed Feb 1, 2020
1 parent 2a7d52f commit a296280
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 100 deletions.
4 changes: 2 additions & 2 deletions esda/moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def by_col(cls, df, events, populations, w=None, inplace=False,
for e,pop,adj in zip(events, populations, adjusted)]
names = ['-'.join((e,p)) for e,p in zip(events, populations)]
out_df = df.copy()
rate_df = out_df.from_items(list(zip(names, rates))) #trick to avoid importing pandas
rate_df = out_df.from_dict(dict(zip(names, rates))) #trick to avoid importing pandas
stat_df = _univariate_handler(rate_df, names, w=w, inplace=False,
pvalue = pvalue, outvals = outvals,
swapname=swapname,
Expand Down Expand Up @@ -1397,7 +1397,7 @@ def by_col(cls, df, events, populations, w=None, inplace=False,
for e,pop,adj in zip(events, populations, adjusted)]
names = ['-'.join((e,p)) for e,p in zip(events, populations)]
out_df = df.copy()
rate_df = out_df.from_items(list(zip(names, rates))) #trick to avoid importing pandas
rate_df = out_df.from_dict(dict(zip(names, rates))) #trick to avoid importing pandas
_univariate_handler(rate_df, names, w=w, inplace=True,
pvalue = pvalue, outvals = outvals,
swapname=swapname,
Expand Down
6 changes: 3 additions & 3 deletions esda/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,8 @@ def by_col(cls, df, e,b, w=None, s=None, **kwargs):
max_len = 0 if len(this_r) > max_len else max_len
rdf.append((outcol, this_r.tolist()))
padded = (r[1] + [None] * max_len for r in rdf)
rdf = list(zip((r[0] for r in rdf), padded))
rdf = pd.DataFrame.from_items(rdf)
rdf = dict(zip((r[0] for r in rdf), padded))
rdf = pd.DataFrame.from_dict(rdf)
return rdf


Expand Down Expand Up @@ -1586,7 +1586,7 @@ def by_col(cls, df, e, b, x_grid, y_grid, geom_col='geometry', **kwargs):
items = [(name, col) for name,col in zip(colnames, [grid[:,0],
grid[:,1],
r.r])]
res.append(pd.DataFrame.from_items(items))
res.append(pd.DataFrame.from_dict(dict(items)))
outdf = pd.concat(res)
return outdf

Expand Down
1 change: 1 addition & 0 deletions esda/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _bivariate_handler(df, x, y=None, w=None, inplace=True, pvalue='sim',
_univariate_handler(df, cols=xi, w=w, y=df[yi], inplace=True,
pvalue=pvalue, outvals=outvals, swapname='', **kwargs)
if real_swapname != '':

df.columns = [_swap_ending(col, real_swapname)
if col.endswith('_statistic')
else col for col in df.columns]
Expand Down
Empty file removed tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/test_gamma.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import numpy as np
from libpysal.weights.util import lat2W
from ..gamma import Gamma
from esda.gamma import Gamma
from libpysal.common import pandas

PANDAS_EXTINCT = pandas is None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_geary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from libpysal import examples
from libpysal.common import pandas

from .. import geary
from esda import geary
import numpy as np

PANDAS_EXTINCT = pandas is None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_getisord.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import numpy as np

from .. import getisord
from esda import getisord
from libpysal.weights.distance import DistanceBand
from libpysal.common import pandas

Expand Down
2 changes: 1 addition & 1 deletion tests/test_join_counts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import numpy as np

from ..join_counts import Join_Counts
from esda.join_counts import Join_Counts
from libpysal.weights.util import lat2W
from libpysal.common import pandas

Expand Down
2 changes: 1 addition & 1 deletion tests/test_mixture_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import numpy as np
import libpysal
from .. import mixture_smoothing as m_s
from esda import mixture_smoothing as m_s


class MS_Tester(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_moran.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import libpysal
from libpysal.common import pandas, RTOL, ATOL
from .. import moran
from esda import moran
import numpy as np


Expand Down Expand Up @@ -32,14 +32,14 @@ def test_variance(self):
mi = moran.Moran(y, w, transformation='B')
np.testing.assert_allclose(mi.VI_rand, 0.059687500000000004, atol=ATOL, rtol=RTOL)
np.testing.assert_allclose(mi.VI_norm, 0.053125000000000006, atol=ATOL, rtol=RTOL)

def test_z_consistency(self):
m1 = moran.Moran(self.y, self.w)
# m2 = moran.Moran_BV(self.x, self.y, self.w) TODO testing for other.z values
m3 = moran.Moran_Local(self.y, self.w)
# m4 = moran.Moran_Local_BV(self.x, self.y, self.w)
np.testing.assert_allclose(m1.z, m3.z, atol=ATOL, rtol=RTOL)


@unittest.skipIf(PANDAS_EXTINCT, 'missing pandas')
def test_by_col(self):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_silhouette.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .. import silhouettes

from esda import silhouettes
import geopandas
import libpysal
import numpy
Expand Down Expand Up @@ -57,7 +56,7 @@ def test_boundary(self):
metric=self.precomputed)
numpy.testing.assert_allclose(known, test, rtol=RTOL, atol=ATOL)
with self.assertRaises(AssertionError):
silhouettes.boundary_silhouette(self.X, self.groups, self.w,
silhouettes.boundary_silhouette(self.X, self.groups, self.w,
metric=self.precomputed - self.precomputed.mean())

def test_path(self):
Expand All @@ -81,11 +80,11 @@ def test_path(self):
-0.03874118,
0.28623703,
0.40062121])
test = silhouettes.path_silhouette(self.X, self.groups, self.w,
test = silhouettes.path_silhouette(self.X, self.groups, self.w,
metric=self.altmetric)
numpy.testing.assert_allclose(known, test, rtol=RTOL, atol=ATOL)
with self.assertRaises(TypeError):
silhouettes.path_silhouette(self.X, self.groups, self.w,
silhouettes.path_silhouette(self.X, self.groups, self.w,
metric=self.precomputed)
with self.assertRaises(AssertionError):
silhouettes.path_silhouette(self.X, self.groups, self.w,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_smaup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
import libpysal
from libpysal.common import pandas, RTOL, ATOL
from ..smaup import Smaup
from ..moran import Moran
from esda.smaup import Smaup
from esda.moran import Moran
import numpy as np


Expand All @@ -17,7 +17,7 @@ def setup(self):
self.rho = Moran(self.y, self.w).I
self.n = len(self.y)
self.k = int(self.n/2)

def test_smaup(self):
self.setup()
sm = Smaup(self.n, self.k, self.rho)
Expand All @@ -29,22 +29,22 @@ def test_smaup(self):
self.assertAlmostEqual(sm.critical_05, 0.3557221333333333)
self.assertAlmostEqual(sm.critical_1, 0.3157950666666666)
self.assertEqual(sm.summary, 'Pseudo p-value > 0.10 (H0 is not rejected)')

def test_sids(self):
from esda import moran
w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read()
f = libpysal.io.open(libpysal.examples.get_path("sids2.dbf"))
SIDR = np.array(f.by_col("SIDR74"))
rho = moran.Moran(SIDR, w, two_tailed=False).I
n = len(SIDR)
k = int(n/2)
k = int(n/2)
sm = Smaup(n, k, rho)
np.testing.assert_allclose(sm.smaup, 0.15176796553181948, rtol=RTOL, atol=ATOL)
self.assertAlmostEqual(sm.critical_01, 0.23404000000000003)
self.assertAlmostEqual(sm.critical_05, 0.21088)
self.assertAlmostEqual(sm.critical_1, 0.18239)
self.assertEqual(sm.summary, 'Pseudo p-value > 0.10 (H0 is not rejected)')

@unittest.skipIf(PANDAS_EXTINCT, 'missing pandas')
def test_by_col(self):
from libpysal.io import geotable as pdio
Expand Down
4 changes: 2 additions & 2 deletions tests/test_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import libpysal
from libpysal.weights.distance import KNN, Kernel
from .. import smoothing as sm
from esda import smoothing as sm
import numpy as np
from libpysal.common import RTOL, ATOL, pandas

Expand Down Expand Up @@ -293,7 +293,7 @@ def test_Headbanging_Triples(self):
self.assertEqual(len(htr.r), len(self.e))
for i in htr.r:
self.assertTrue(i is not None)

@unittest.skip('Deprecated')
def test_Headbanging_Median_Rate(self):
s_ht = sm.Headbanging_Triples(self.d, self.w, k=5)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import libpysal
from .. import util
from .. import moran
from esda import util
from esda import moran
import numpy as np

class Fdr_Tester(unittest.TestCase):
Expand Down
Loading

0 comments on commit a296280

Please sign in to comment.