Repository: geopandas/geopandas

Issue:
Pandas SQL API change breaks read_postgis()
As discovered in #97, pandas [PR#6867](https://github.com/pydata/pandas/pull/6867) changed the `read_sql()` API in a way that breaks `read_postgis()` and tests.  A change to get GeoPandas working again with pandas master is in 75c530115e, but it needs to be cleaned up to make it backward compatible with released pandas versions.



Discussion:

Resolving patch:
diff --git a/geopandas/io/sql.py b/geopandas/io/sql.py
--- a/geopandas/io/sql.py
+++ b/geopandas/io/sql.py
@@ -3,9 +3,9 @@
 from pandas import read_sql
 import shapely.wkb
 
-
 from geopandas import GeoSeries, GeoDataFrame
 
+
 def read_postgis(sql, con, geom_col='geom', crs=None, index_col=None,
                  coerce_float=True, params=None):
     """
@@ -19,7 +19,7 @@ def read_postgis(sql, con, geom_col='geom', crs=None, index_col=None,
     Parameters
     ----------
     sql: string
-    con: DB connection object
+    con: DB connection object or SQLAlchemy engine
     geom_col: string, default 'geom'
         column name to convert to shapely geometries
     crs: optional
@@ -30,8 +30,9 @@ def read_postgis(sql, con, geom_col='geom', crs=None, index_col=None,
     index_col, coerce_float, params
 
     """
-    df = read_sql(sql, con, index_col=index_col, coerce_float=coerce_float, 
+    df = read_sql(sql, con, index_col=index_col, coerce_float=coerce_float,
                   params=params)
+
     if geom_col not in df:
         raise ValueError("Query missing geometry column '{0}'".format(
             geom_col))


Test patch:
diff --git a/requirements.test.txt b/requirements.test.txt
--- a/requirements.test.txt
+++ b/requirements.test.txt
@@ -1,4 +1,5 @@
 psycopg2>=2.5.1
+SQLAlchemy>=0.8.3
 geopy==0.99
 matplotlib>=1.2.1
 descartes>=1.0
diff --git a/tests/test_geodataframe.py b/tests/test_geodataframe.py
--- a/tests/test_geodataframe.py
+++ b/tests/test_geodataframe.py
@@ -367,8 +367,6 @@ def test_from_features_unaligned_properties(self):
                                            {'a': 2, 'b': np.nan}])
         assert_frame_equal(expected, result)
 
-    @unittest.skipIf(PANDAS_NEW_SQL_API, 'Development version of pandas '
-                     'not yet supported in SQL API.')
     def test_from_postgis_default(self):
         con = connect('test_geopandas')
         if con is None or not create_db(self.df):
@@ -378,12 +376,13 @@ def test_from_postgis_default(self):
             sql = "SELECT * FROM nybb;"
             df = GeoDataFrame.from_postgis(sql, con)
         finally:
+            if PANDAS_NEW_SQL_API:
+                # It's not really a connection, it's an engine
+                con = con.connect()
             con.close()
 
         validate_boro_df(self, df)
 
-    @unittest.skipIf(PANDAS_NEW_SQL_API, 'Development version of pandas '
-                     'not yet supported in SQL API.')
     def test_from_postgis_custom_geom_col(self):
         con = connect('test_geopandas')
         if con is None or not create_db(self.df):
@@ -396,6 +395,9 @@ def test_from_postgis_custom_geom_col(self):
                      FROM nybb;"""
             df = GeoDataFrame.from_postgis(sql, con, geom_col='__geometry__')
         finally:
+            if PANDAS_NEW_SQL_API:
+                # It's not really a connection, it's an engine
+                con = con.connect()
             con.close()
 
         validate_boro_df(self, df)
diff --git a/tests/test_io.py b/tests/test_io.py
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -16,8 +16,6 @@ def setUp(self):
         with fiona.open(path, vfs=vfs) as f:
             self.crs = f.crs
 
-    @unittest.skipIf(PANDAS_NEW_SQL_API, 'Development version of pandas '
-                     'not yet supported in SQL API.')
     def test_read_postgis_default(self):
         con = tests.util.connect('test_geopandas')
         if con is None or not tests.util.create_db(self.df):
@@ -27,12 +25,13 @@ def test_read_postgis_default(self):
             sql = "SELECT * FROM nybb;"
             df = read_postgis(sql, con)
         finally:
+            if PANDAS_NEW_SQL_API:
+                # It's not really a connection, it's an engine
+                con = con.connect()
             con.close()
 
         tests.util.validate_boro_df(self, df)
 
-    @unittest.skipIf(PANDAS_NEW_SQL_API, 'Development version of pandas '
-                     'not yet supported in SQL API.')
     def test_read_postgis_custom_geom_col(self):
         con = tests.util.connect('test_geopandas')
         if con is None or not tests.util.create_db(self.df):
@@ -45,6 +44,9 @@ def test_read_postgis_custom_geom_col(self):
                      FROM nybb;"""
             df = read_postgis(sql, con, geom_col='__geometry__')
         finally:
+            if PANDAS_NEW_SQL_API:
+                # It's not really a connection, it's an engine
+                con = con.connect()
             con.close()
 
         tests.util.validate_boro_df(self, df)