internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: geopandas/geopandas

Issue:
DOC: update the contextily example in the gallery
The example about adding a background map to your plot using contextily at https://geopandas.readthedocs.io/en/latest/gallery/plotting_basemap_background.html#sphx-glr-gallery-plotting-basemap-background-py can be updated with the latest contextily (https://github.com/darribas/contextily/releases/tag/v1.0rc2).

For example, the `add_basemap` function is now available in contextily itself.


Discussion:

Resolving patch:
diff --git a/examples/plotting_basemap_background.py b/examples/plotting_basemap_background.py
--- a/examples/plotting_basemap_background.py
+++ b/examples/plotting_basemap_background.py
@@ -1,5 +1,5 @@
 """
-Adding a background map to plots 
+Adding a background map to plots
 --------------------------------
 
 This example shows how you can add a background basemap to plots created
@@ -31,38 +31,31 @@
 df = df.to_crs(epsg=3857)
 
 ###############################################################################
-# Contextily helper function
-# ==========================
-#
-# We define a small helper function that uses
-# `contextily <https://github.com/darribas/contextily>`__ to add a map
-# as background to an existing plot: 
 
 import contextily as ctx
 
-def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png'):
-    xmin, xmax, ymin, ymax = ax.axis()
-    basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url)
-    ax.imshow(basemap, extent=extent, interpolation='bilinear')
-    # restore original x/y limits
-    ax.axis((xmin, xmax, ymin, ymax))
-
 ###############################################################################
 # Add background tiles to plot
 # ============================
 #
-# Now we can use the above function to easily add a background map to our
-# plot. The `zoom` keyword is required and let's you specify the detail of the
-# map tiles (be careful to not specify a too high `zoom` level, as this can
-# result in a large download):
+# We can use `add_basemap` function of contextily to easily add a background
+# map to our plot. :
+
+ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
+ctx.add_basemap(ax)
+
+###############################################################################
+# We can control the detail of the map tiles using the optional `zoom` keyword
+# (be careful to not specify a too high `zoom` level,
+# as this can result in a large download).:
 
 ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
-add_basemap(ax, zoom=10)
+ctx.add_basemap(ax, zoom=12)
 
 ###############################################################################
 # By default, contextily uses the Stamen Terrain style. We can specify a
-# different style using ``ctx.sources``:
+# different style using ``ctx.providers``:
 
 ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
-add_basemap(ax, zoom=11, url=ctx.sources.ST_TONER_LITE)
+ctx.add_basemap(ax, url=ctx.providers.Stamen.TonerLite)
 ax.set_axis_off()


Test patch:
Repository: geopandas/geopandas

Issue:
Lat Long order is wrong in WKT example
In regards to documentation of converting WKT format to geopandas GeoDataFrame, the order of LAT LONG is wrong.
See #690 
In the WKT POINT, you put the Lat first, amd then Long. It should be the opposite. 
When plotting the WKT example, and comparing it to the simple Long Lat example, you can clearly see that the WKT points are not placed where they should be.

From what I understand, WKT should follow the WGS84 standard.
See for example: https://www.drupal.org/project/geo/issues/511370


Discussion:
Offending lines are: https://github.com/geopandas/geopandas/blob/a20ac9c816e809fa021ed5fb7309b7f09b2acb64/examples/create_geopandas_from_pandas.py#L64-L69

Plotting the GeoDataFrame for the example would be a good idea too.

Resolving patch:
diff --git a/examples/create_geopandas_from_pandas.py b/examples/create_geopandas_from_pandas.py
--- a/examples/create_geopandas_from_pandas.py
+++ b/examples/create_geopandas_from_pandas.py
@@ -51,7 +51,7 @@
 ax = world[world.continent == 'South America'].plot(
     color='white', edgecolor='black')
 
-# We can now plot our GeoDataFrame.
+# We can now plot our ``GeoDataFrame``.
 gdf.plot(ax=ax, color='red')
 
 plt.show()
@@ -64,9 +64,9 @@
 df = pd.DataFrame(
     {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
      'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
-     'Coordinates': ['POINT(-34.58 -58.66)', 'POINT(-15.78 -47.91)',
-                     'POINT(-33.45 -70.66)', 'POINT(4.60 -74.08)',
-                     'POINT(10.48 -66.86)']})
+     'Coordinates': ['POINT(-58.66 -34.58)', 'POINT(-47.91 -15.78)',
+                     'POINT(-70.66 -33.45)', 'POINT(-74.08 4.60)',
+                     'POINT(-66.86 10.48)']})
 
 ###############################################################################
 # We use ``shapely.wkt`` sub-module to parse wkt format:
@@ -80,3 +80,9 @@
 gdf = geopandas.GeoDataFrame(df, geometry='Coordinates')
 
 print(gdf.head())
+
+#################################################################################
+# Again, we can plot our ``GeoDataFrame``.
+gdf.plot(ax=ax, color='red')
+
+plt.show()


Test patch:
Repository: geopandas/geopandas

Issue:
Writing to file doesn't respect fiona vsi schemes
Fiona supports writing to different OGR virtual filesystem schemes via the file path, e.g., `zip://`, `s3://`, etc. However, these schemes get overwritten in `gpd.to_file()`, which attempts to take the path and construct an absolute path:
https://github.com/geopandas/geopandas/blob/29add0a735b00dc20c79e0fccc8e6a775c4997b0/geopandas/io/file.py#L127
so you get bad paths like `/home/username/s3:/bucket/object`.

Is this absolute file path important? Is there a reason to not allow VSI-based paths in `gpd.to_file()`? Can we check for a url-like scheme before trying to abs-path it? If so, I'd be happy to submit a PR.

(N.b., the corresponding `gpd.read_file()` handles these URLs correctly).


Discussion:
That is a good point. I don't think there is any reason not to allow VSI-based paths, it just wasn't implemented yet. 

> Can we check for a url-like scheme before trying to abs-path it? If so, I'd be happy to submit a PR.

PRs are always welcome. Feel free to do so. Thanks!

Resolving patch:
diff --git a/geopandas/io/file.py b/geopandas/io/file.py
--- a/geopandas/io/file.py
+++ b/geopandas/io/file.py
@@ -1,5 +1,4 @@
 from distutils.version import LooseVersion
-import os
 
 import numpy as np
 import six
@@ -120,10 +119,10 @@ def to_file(df, filename, driver="ESRI Shapefile", schema=None, **kwargs):
 
     The *kwargs* are passed to fiona.open and can be used to write
     to multi-layer data, store data within archives (zip files), etc.
+    The path may specify a fiona VSI scheme.
     """
     if schema is None:
         schema = infer_schema(df)
-    filename = os.path.abspath(os.path.expanduser(filename))
     with fiona_env():
         with fiona.open(
             filename, "w", driver=driver, crs=df.crs, schema=schema, **kwargs


Test patch:
Repository: geopandas/geopandas

Issue:
BUG: GeoSeries.reset_index() gives DataFrame not GeoDataFrame
Having GeoSeries with MultiIndex, GeoSeries.reset_index() returns pandas DataFrame not GeoDataFrame as I would expect in such a case. 

```python
import geopandas as gpd
gpd.__version__
```




    '0.6.1+17.g1132cc8'




```python
nybb = gpd.read_file(gpd.datasets.get_path('nybb'))
geoms = nybb.geometry
geoms = geoms.explode()  # nybb has multipolygons, so we get multiindex
type(geoms)
```




    geopandas.geoseries.GeoSeries




```python
geoms = geoms.reset_index()
type(geoms)
```




    pandas.core.frame.DataFrame








Discussion:
We might be able to fix this by defining `GeoSeries._constructor_expanddim` to be GeoDataFrame (instead of needing to override `reset_index` on GeoSeries). That's at least being used in `Series.to_frame`, which is being used in `Series.reset_index`(but should need to check in what other cases this `_constructor_expanddim` is being used).

Resolving patch:
diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py
--- a/geopandas/geoseries.py
+++ b/geopandas/geoseries.py
@@ -220,6 +220,12 @@ def to_file(self, filename, driver="ESRI Shapefile", **kwargs):
     def _constructor(self):
         return _geoseries_constructor_with_fallback
 
+    @property
+    def _constructor_expanddim(self):
+        from geopandas import GeoDataFrame
+
+        return GeoDataFrame
+
     def _wrapped_pandas_method(self, mtd, *args, **kwargs):
         """Wrap a generic pandas method to ensure it returns a GeoSeries"""
         val = getattr(super(GeoSeries, self), mtd)(*args, **kwargs)


Test patch:
diff --git a/geopandas/tests/test_geoseries.py b/geopandas/tests/test_geoseries.py
--- a/geopandas/tests/test_geoseries.py
+++ b/geopandas/tests/test_geoseries.py
@@ -18,7 +18,7 @@
 )
 from shapely.geometry.base import BaseGeometry
 
-from geopandas import GeoSeries
+from geopandas import GeoSeries, GeoDataFrame
 from geopandas.array import GeometryArray, GeometryDtype
 
 from geopandas.tests.util import geom_equals
@@ -324,3 +324,12 @@ def test_from_series(self):
         assert [a.equals(b) for a, b in zip(s, g)]
         assert s.name == g.name
         assert s.index is g.index
+
+    # GH 1216
+    def test_expanddim(self):
+        s = GeoSeries(
+            [MultiPoint([(0, 0), (1, 1)]), MultiPoint([(2, 2), (3, 3), (4, 4)])]
+        )
+        s = s.explode()
+        df = s.reset_index()
+        assert type(df) == GeoDataFrame
Repository: geopandas/geopandas

Issue:
DOC: missing changelog in documentation
Our changelog is available only as a .md file in the root folder. It should be part of the documentation online as well as @StevenLi-DS correctly pointed out in https://github.com/geopandas/geopandas/issues/1076#issuecomment-590126250.


Discussion:
Can I pick this up?
Feel free to do so. If you find a way hot to get it automatically from CHANGELOG.md that would be ideal.

Resolving patch:
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -32,6 +32,7 @@
               'sphinx.ext.autosummary',
               'sphinx.ext.intersphinx',
               'sphinx.ext.autodoc',
+              'recommonmark',
               'numpydoc',
 ]
 
@@ -79,7 +80,7 @@ def setup(app):
 )
 
 # The suffix of source filenames.
-source_suffix = '.rst'
+source_suffix = ['.rst', '.md']
 
 # The encoding of source files.
 #source_encoding = 'utf-8-sig'


Test patch:
Repository: geopandas/geopandas

Issue:
total_bounds return np.nan if there is None in GeoSeries
If GeoSeries contains None, `total_bounds` return array of np.nan, instead of values. 

```
s = gpd.GeoSeries([Point(0,0), Point(1,1), None])
s.total_bounds

> array([nan, nan, nan, nan])
```

The original implementation used `np.nanmin` and `np.nanmax` to ignore nan and return the extent of existing geometries, which changed in #48 to existing solution, but I believe unintentionally. Is there a reason why we should return NaNs instead of bounds of existing geometries? It is just a question of changing this https://github.com/geopandas/geopandas/blob/196902feeaec2acd65bec4832704a8196f4d3b0d/geopandas/array.py#L791-L794

to this:

```py
np.nanmin(b[:, 0]),  # minx
np.nanmin(b[:, 1]),  # miny
np.nanmax(b[:, 2]),  # maxx
np.nanmax(b[:, 3]),  # maxy
```

There does not seem to be any performance penalty either:

<img width="574" alt="Snímek obrazovky 2020-02-25 v 23 07 13" src="https://user-images.githubusercontent.com/36797143/75295841-91b6d700-5823-11ea-89b2-2185dfd9c562.png">



Discussion:

Resolving patch:
diff --git a/geopandas/array.py b/geopandas/array.py
--- a/geopandas/array.py
+++ b/geopandas/array.py
@@ -788,12 +788,12 @@ def total_bounds(self):
         b = self.bounds
         return np.array(
             (
-                b[:, 0].min(),  # minx
-                b[:, 1].min(),  # miny
-                b[:, 2].max(),  # maxx
-                b[:, 3].max(),
+                np.nanmin(b[:, 0]),  # minx
+                np.nanmin(b[:, 1]),  # miny
+                np.nanmax(b[:, 2]),  # maxx
+                np.nanmax(b[:, 3]),  # maxy
             )
-        )  # maxy
+        )
 
     # -------------------------------------------------------------------------
     # general array like compat


Test patch:
diff --git a/geopandas/tests/test_array.py b/geopandas/tests/test_array.py
--- a/geopandas/tests/test_array.py
+++ b/geopandas/tests/test_array.py
@@ -635,10 +635,10 @@ def test_total_bounds():
     )
     expected = np.array(
         [
-            bounds[:, 0].min(),  # minx
-            bounds[:, 1].min(),  # miny
-            bounds[:, 2].max(),  # maxx
-            bounds[:, 3].max(),  # maxy
+            np.nanmin(bounds[:, 0]),  # minx
+            np.nanmin(bounds[:, 1]),  # miny
+            np.nanmax(bounds[:, 2]),  # maxx
+            np.nanmax(bounds[:, 3]),  # maxy
         ]
     )
     np.testing.assert_allclose(result, expected)
Repository: geopandas/geopandas

Issue:
DOC: update read_postgis docstring for CRS changes
The read_postgis docstring still mentions to use a dict:

https://github.com/geopandas/geopandas/blob/078062d303e401aaa5e37e04c0e7c3ce188920fe/geopandas/io/sql.py#L33-L36

we should update this to follow how CRS is explained in other places now we use pyproj.


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
@@ -30,10 +30,12 @@ def read_postgis(
         Active connection to the database to query.
     geom_col : string, default 'geom'
         column name to convert to shapely geometries
-    crs : dict or str, optional
-        CRS to use for the returned GeoDataFrame; if not set, tries to
-        determine CRS from the SRID associated with the first geometry in
-        the database, and assigns that to all geometries.
+    crs : pyproj.CRS, optional
+        CRS to use for the returned GeoDataFrame. The value can be anything accepted
+        by :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
+        such as an authority string (eg "EPSG:4326") or a WKT string.
+        If not set, tries to determine CRS from the SRID associated with the
+        first geometry in the database, and assigns that to all geometries.
 
     See the documentation for pandas.read_sql for further explanation
     of the following parameters:


Test patch:
Repository: geopandas/geopandas

Issue:
Handle the new pd.NA value as missing value
From https://github.com/geopandas/geopandas/pull/1154/files#r392596021, we have a custom `_isna` function to recognize missing value scalars. We should update this function to also deal with the new `pd.NA` scalar.


Discussion:

Resolving patch:
diff --git a/geopandas/array.py b/geopandas/array.py
--- a/geopandas/array.py
+++ b/geopandas/array.py
@@ -55,7 +55,7 @@ def construct_array_type(cls):
 
 def _isna(value):
     """
-    Check if scalar value is NA-like (None or np.nan).
+    Check if scalar value is NA-like (None, np.nan or pd.NA).
 
     Custom version that only works for scalars (returning True or False),
     as `pd.isna` also works for array-like input returning a boolean array.
@@ -64,6 +64,8 @@ def _isna(value):
         return True
     elif isinstance(value, float) and np.isnan(value):
         return True
+    elif compat.PANDAS_GE_10 and value is pd.NA:
+        return True
     else:
         return False
 


Test patch:
diff --git a/geopandas/tests/test_array.py b/geopandas/tests/test_array.py
--- a/geopandas/tests/test_array.py
+++ b/geopandas/tests/test_array.py
@@ -822,3 +822,17 @@ def test_check_crs():
     assert _check_crs(t1, T) is False
     assert _check_crs(t1, t1) is True
     assert _check_crs(t1, T, allow_none=True) is True
+
+
+@pytest.mark.parametrize("NA", [None, np.nan])
+def test_isna(NA):
+    t1 = T.copy()
+    t1[0] = NA
+    assert t1[0] is None
+
+
+@pytest.mark.skipif(not compat.PANDAS_GE_10, reason="pd.NA introduced in pandas 1.0")
+def test_isna_pdNA():
+    t1 = T.copy()
+    t1[0] = pd.NA
+    assert t1[0] is None
Repository: geopandas/geopandas

Issue:
Warn when writing to Shapefile will change column names
I used gpd.to_file to save my geo dataframe object into a shapefile. However some of my column names have changed. Does anyone know why that occurred and how to fix that? I can rename the columns back to their original names but it would be good to know why that happened.

`sample_target0_ff.to_file(out_path+'shp/sample_target0_ff.shp', driver='ESRI Shapefile')
`
and the name is changed from "ignition_id" to "ignition_i" and from "pbi_grid_id" to "pbi_grid_i" 


Discussion:
Just noted that someone mentioned that only 10 characters are allowed. if it is nto the case, can someone suggest what other reasons could be?
Indeed, see eg "Maximum length of field names is 10 characters" at https://en.wikipedia.org/wiki/Shapefile#Limitations

We could actually detect this and raise a warning, if we want (since regularly people run into this issue). 
And we should maybe also better document it in our own docs, although it is a general Shapefile issue.


Resolving patch:
diff --git a/geopandas/io/file.py b/geopandas/io/file.py
--- a/geopandas/io/file.py
+++ b/geopandas/io/file.py
@@ -1,6 +1,7 @@
 from distutils.version import LooseVersion
 
 import io
+import warnings
 import numpy as np
 import pandas as pd
 
@@ -241,6 +242,14 @@ def _to_file(
         crs = pyproj.CRS.from_user_input(crs)
     else:
         crs = df.crs
+
+    if driver == "ESRI Shapefile" and any([len(c) > 10 for c in df.columns.tolist()]):
+        warnings.warn(
+            "Column names longer than 10 characters will be truncated when saved to "
+            "ESRI Shapefile.",
+            stacklevel=3,
+        )
+
     with fiona_env():
         crs_wkt = None
         try:


Test patch:
diff --git a/geopandas/io/tests/test_file.py b/geopandas/io/tests/test_file.py
--- a/geopandas/io/tests/test_file.py
+++ b/geopandas/io/tests/test_file.py
@@ -243,6 +243,22 @@ def test_to_file_schema(tmpdir, df_nybb):
     assert result_schema == schema
 
 
+def test_to_file_column_len(tmpdir, df_points):
+    """
+    Ensure that a warning about truncation is given when a geodataframe with
+    column names longer than 10 characters is saved to shapefile
+    """
+    tempfilename = os.path.join(str(tmpdir), "test.shp")
+
+    df = df_points.iloc[:1].copy()
+    df["0123456789A"] = ["the column name is 11 characters"]
+
+    with pytest.warns(
+        UserWarning, match="Column names longer than 10 characters will be truncated"
+    ):
+        df.to_file(tempfilename, driver="ESRI Shapefile")
+
+
 @pytest.mark.parametrize("driver,ext", driver_ext_pairs)
 def test_append_file(tmpdir, df_nybb, df_null, driver, ext):
     """ Test to_file with append mode and from_file """
Repository: geopandas/geopandas

Issue:
to_postgis raises spurious warning
Very happy about the new `to_postgis` function in 0.8. I found that it works as expected, but it raises a spurious warning. It creates a temporary copy of the GeoDataFrame with geometry columns converted to WKB. This temporary copy fails a check that the geometry columns must actually contain geometry objects, and raises a `UserWarning`:

```python
lib/python3.8/site-packages/geopandas/geodataframe.py:830: UserWarning: Geometry column does not contain geometry.
  warnings.warn("Geometry column does not contain geometry.")
```

Here is a MWE (note: the insert will fail without an actual backing postgis database, but this raises the user warning before failing):
```python
import geopandas
import shapely
import sqlalchemy

gdf = geopandas.GeoDataFrame(geometry=[shapely.geometry.Point(0,0)])
engine = sqlalchemy.create_engine("postgres://user:password@localhost:5432/db")
gdf.to_postgis("tablename", engine)
```

It should be relatively straightforward to filter this warning, since I don't think it applies here, happy to open a PR to that effect.


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
@@ -248,8 +248,12 @@ def _convert_to_ewkb(gdf, geom_name, srid):
 
         geoms = [dumps(geom, srid=srid, hex=True) for geom in gdf[geom_name]]
 
-    gdf[geom_name] = geoms
-    return gdf
+    # The gdf will warn that the geometry column doesn't hold in-memory geometries
+    # now that they are EWKB, so convert back to a regular dataframe to avoid warning
+    # the user that the dtypes are unexpected.
+    df = pd.DataFrame(gdf, copy=False)
+    df[geom_name] = geoms
+    return df
 
 
 def _psql_insert_copy(tbl, conn, keys, data_iter):


Test patch:
Repository: geopandas/geopandas

Issue:
BUG: test_numerical_operations fails under pandas 1.1.0
[Failure](https://travis-ci.org/github/geopandas/geopandas/jobs/712675986#L2140) in `test_numerical_operations` (`idxmin` error type) -> pandas-dev/pandas#32749. Even though it is a known regression in pandas, we should handle it (at least skip tests for now).


Discussion:

Resolving patch:
diff --git a/geopandas/_compat.py b/geopandas/_compat.py
--- a/geopandas/_compat.py
+++ b/geopandas/_compat.py
@@ -12,7 +12,7 @@
 
 PANDAS_GE_025 = str(pd.__version__) >= LooseVersion("0.25.0")
 PANDAS_GE_10 = str(pd.__version__) >= LooseVersion("0.26.0.dev")
-PANDAS_GE_11 = str(pd.__version__) >= LooseVersion("1.1.0.dev")
+PANDAS_GE_11 = str(pd.__version__) >= LooseVersion("1.1.0")
 
 
 # -----------------------------------------------------------------------------


Test patch:
diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py
--- a/geopandas/tests/test_pandas_methods.py
+++ b/geopandas/tests/test_pandas_methods.py
@@ -272,14 +272,15 @@ def test_numerical_operations(s, df):
     exp = pd.Series([3, 4], index=["value1", "value2"])
     assert_series_equal(df.sum(), exp)
 
-    # series methods raise error
+    # series methods raise error (not supported for geometry)
     with pytest.raises(TypeError):
         s.sum()
 
     with pytest.raises(TypeError):
         s.max()
 
-    with pytest.raises(TypeError):
+    with pytest.raises((TypeError, ValueError)):
+        # TODO: remove ValueError after pandas-dev/pandas#32749
         s.idxmax()
 
     # numerical ops raise an error