mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-23 13:20:36 +08:00
Fix most flake8 issues (F821 missing)
This commit is contained in:
committed by
Joris Van den Bossche
parent
7bc3166cfe
commit
f4b749d148
+12
-12
@@ -1,20 +1,20 @@
|
||||
from geopandas.geoseries import GeoSeries
|
||||
from geopandas.geodataframe import GeoDataFrame
|
||||
from geopandas.array import _points_from_xy as points_from_xy
|
||||
from geopandas.geoseries import GeoSeries # noqa
|
||||
from geopandas.geodataframe import GeoDataFrame # noqa
|
||||
from geopandas.array import _points_from_xy as points_from_xy # noqa
|
||||
|
||||
from geopandas.io.file import read_file
|
||||
from geopandas.io.sql import read_postgis
|
||||
from geopandas.tools import sjoin
|
||||
from geopandas.tools import overlay
|
||||
from geopandas.tools._show_versions import show_versions
|
||||
from geopandas.io.file import read_file # noqa
|
||||
from geopandas.io.sql import read_postgis # noqa
|
||||
from geopandas.tools import sjoin # noqa
|
||||
from geopandas.tools import overlay # noqa
|
||||
from geopandas.tools._show_versions import show_versions # noqa
|
||||
|
||||
import geopandas.datasets
|
||||
import geopandas.datasets # noqa
|
||||
|
||||
# make the interactive namespace easier to use
|
||||
# for `from geopandas import *` demos.
|
||||
import geopandas as gpd
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import geopandas as gpd # noqa
|
||||
import pandas as pd # noqa
|
||||
import numpy as np # noqa
|
||||
|
||||
from ._version import get_versions
|
||||
|
||||
|
||||
+1
-1
@@ -372,7 +372,7 @@ def _unary_geo(op, left, *args, **kwargs):
|
||||
|
||||
|
||||
def _unary_op(op, left, null_value=False):
|
||||
# type: (str, GeometryArray, Any) -> array
|
||||
# type: (str, GeometryArray, Any) -> np.array
|
||||
"""Unary operation that returns a Series"""
|
||||
data = [getattr(geom, op, null_value) for geom in left.data]
|
||||
return np.array(data, dtype=np.dtype(type(null_value)))
|
||||
|
||||
+6
-6
@@ -3,12 +3,10 @@ from warnings import warn
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas import Series, DataFrame, MultiIndex
|
||||
from pandas.core.indexing import _NDFrameIndexer
|
||||
|
||||
from shapely.geometry.base import BaseGeometry
|
||||
from shapely.geometry import box
|
||||
from shapely.ops import cascaded_union, unary_union
|
||||
import shapely.affinity as affinity
|
||||
|
||||
import geopandas as gpd
|
||||
|
||||
@@ -628,9 +626,11 @@ class GeoPandasBase(object):
|
||||
----------
|
||||
matrix: List or tuple
|
||||
6 or 12 items for 2D or 3D transformations respectively.
|
||||
For 2D affine transformations, the 6 parameter matrix is [a, b, d, e, xoff, yoff]
|
||||
For 3D affine transformations, the 12 parameter matrix is [a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]
|
||||
"""
|
||||
For 2D affine transformations,
|
||||
the 6 parameter matrix is [a, b, d, e, xoff, yoff]
|
||||
For 3D affine transformations,
|
||||
the 12 parameter matrix is [a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]
|
||||
""" # noqa (E501 link is longer than max line length)
|
||||
return _delegate_geo_method("affine_transform", self, matrix)
|
||||
|
||||
def translate(self, xoff=0.0, yoff=0.0, zoff=0.0):
|
||||
@@ -645,7 +645,7 @@ class GeoPandasBase(object):
|
||||
Amount of offset along each dimension.
|
||||
xoff, yoff, and zoff for translation along the x, y, and z
|
||||
dimensions respectively.
|
||||
"""
|
||||
""" # noqa (E501 link is longer than max line length)
|
||||
return _delegate_geo_method("translate", self, xoff, yoff, zoff)
|
||||
|
||||
def rotate(self, angle, origin="center", use_radians=False):
|
||||
|
||||
@@ -3,7 +3,7 @@ Script that generates the included dataset 'naturalearth_lowres.shp'.
|
||||
|
||||
Raw data: https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-0-countries/
|
||||
Current version used: version 4.1.0
|
||||
"""
|
||||
""" # noqa (E501 link is longer than max line length)
|
||||
|
||||
import geopandas as gpd
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ import json
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas import DataFrame, Series
|
||||
from shapely.geometry import mapping, shape, Point
|
||||
from shapely.geometry.base import BaseGeometry
|
||||
from shapely.geometry import mapping, shape
|
||||
from six import string_types, PY3
|
||||
|
||||
from geopandas.array import GeometryArray, from_shapely
|
||||
from geopandas.base import GeoPandasBase, _CoordinateIndexer, is_geometry_type
|
||||
from geopandas.base import GeoPandasBase, is_geometry_type
|
||||
from geopandas.geoseries import GeoSeries
|
||||
from geopandas.plotting import plot_dataframe
|
||||
import geopandas.io
|
||||
@@ -156,7 +155,7 @@ class GeoDataFrame(GeoPandasBase, DataFrame):
|
||||
level = frame[col].values
|
||||
except KeyError:
|
||||
raise ValueError("Unknown column %s" % col)
|
||||
except:
|
||||
except Exception:
|
||||
raise
|
||||
if drop:
|
||||
to_remove = col
|
||||
|
||||
+10
-17
@@ -9,28 +9,19 @@ from pandas import Series
|
||||
from pandas.core.internals import SingleBlockManager
|
||||
|
||||
import pyproj
|
||||
from shapely.geometry import shape, Point
|
||||
from shapely.geometry.base import BaseGeometry
|
||||
from shapely.ops import transform
|
||||
|
||||
from geopandas.plotting import plot_series
|
||||
from geopandas.base import GeoPandasBase, _delegate_property, _CoordinateIndexer
|
||||
from geopandas.base import GeoPandasBase, _delegate_property
|
||||
|
||||
from .array import GeometryArray, GeometryDtype, from_shapely
|
||||
from .array import GeometryDtype, from_shapely
|
||||
from .base import is_geometry_type
|
||||
from ._compat import PANDAS_GE_024
|
||||
|
||||
|
||||
_PYPROJ2 = LooseVersion(pyproj.__version__) >= LooseVersion("2.1.0")
|
||||
|
||||
|
||||
def _is_empty(x):
|
||||
try:
|
||||
return x.is_empty
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
_SERIES_WARNING_MSG = """\
|
||||
You are passing non-geometry data to the GeoSeries constructor. Currently,
|
||||
it falls back to returning a pandas Series. But in the future, we will start
|
||||
@@ -279,14 +270,15 @@ class GeoSeries(GeoPandasBase, Series):
|
||||
"""
|
||||
if self.is_empty.any():
|
||||
warnings.warn(
|
||||
"GeoSeries.isna() previously returned True for both missing (None) and "
|
||||
"empty geometries. Now, it only returns True for missing values. "
|
||||
"GeoSeries.isna() previously returned True for both missing (None) "
|
||||
"and empty geometries. Now, it only returns True for missing values. "
|
||||
"Since the calling GeoSeries contains empty geometries, the result "
|
||||
"has changed compared to previous versions of GeoPandas.\n"
|
||||
"Given a GeoSeries 's', you can use 's.is_empty | s.isna()' to get "
|
||||
"back the old behaviour.\n\n"
|
||||
"To further ignore this warning, you can do: \n"
|
||||
"import warnings; warnings.filterwarnings('ignore', 'GeoSeries.isna', UserWarning)",
|
||||
"import warnings; warnings.filterwarnings('ignore', 'GeoSeries.isna', "
|
||||
"UserWarning)",
|
||||
UserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
@@ -319,14 +311,15 @@ class GeoSeries(GeoPandasBase, Series):
|
||||
"""
|
||||
if self.is_empty.any():
|
||||
warnings.warn(
|
||||
"GeoSeries.notna() previously returned False for both missing (None) and "
|
||||
"empty geometries. Now, it only returns False for missing values. "
|
||||
"GeoSeries.notna() previously returned False for both missing (None) "
|
||||
"and empty geometries. Now, it only returns False for missing values. "
|
||||
"Since the calling GeoSeries contains empty geometries, the result "
|
||||
"has changed compared to previous versions of GeoPandas.\n"
|
||||
"Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get "
|
||||
"back the old behaviour.\n\n"
|
||||
"To further ignore this warning, you can do: \n"
|
||||
"import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)",
|
||||
"import warnings; warnings.filterwarnings('ignore', "
|
||||
"'GeoSeries.notna', UserWarning)",
|
||||
UserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ def _is_url(url):
|
||||
"""Check to see if *url* has a valid protocol."""
|
||||
try:
|
||||
return parse_url(url).scheme in _VALID_URLS
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from enum import Enum
|
||||
|
||||
from shapely.geometry import (
|
||||
|
||||
@@ -122,8 +122,9 @@ class TestIO:
|
||||
geom_col = df_nybb.geometry.name
|
||||
df_nybb.geometry.iat[0] = None
|
||||
create_spatialite(con, df_nybb)
|
||||
sql = 'SELECT ogc_fid, borocode, boroname, shape_leng, shape_area, AsEWKB("{0}") AS "{0}" FROM nybb'.format(
|
||||
geom_col
|
||||
sql = (
|
||||
"SELECT ogc_fid, borocode, boroname, shape_leng, shape_area, "
|
||||
'AsEWKB("{0}") AS "{0}" FROM nybb'.format(geom_col)
|
||||
)
|
||||
df = read_postgis(sql, con, geom_col=geom_col)
|
||||
validate_boro_df(df)
|
||||
@@ -140,8 +141,9 @@ class TestIO:
|
||||
else:
|
||||
geom_col = df_nybb.geometry.name
|
||||
create_spatialite(con, df_nybb)
|
||||
sql = 'SELECT ogc_fid, borocode, boroname, shape_leng, shape_area, ST_AsBinary("{0}") AS "{0}" FROM nybb'.format(
|
||||
geom_col
|
||||
sql = (
|
||||
"SELECT ogc_fid, borocode, boroname, shape_leng, shape_area, "
|
||||
'ST_AsBinary("{0}") AS "{0}" FROM nybb'.format(geom_col)
|
||||
)
|
||||
df = read_postgis(sql, con, geom_col=geom_col)
|
||||
validate_boro_df(df)
|
||||
|
||||
@@ -449,7 +449,6 @@ def plot_dataframe(
|
||||
)
|
||||
column = None
|
||||
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
if ax is None:
|
||||
|
||||
@@ -5,7 +5,7 @@ Testing functionality for geopandas objects.
|
||||
import pandas as pd
|
||||
|
||||
from geopandas import GeoSeries, GeoDataFrame
|
||||
from geopandas.array import GeometryDtype, GeometryArray
|
||||
from geopandas.array import GeometryDtype
|
||||
|
||||
|
||||
def _isna(this):
|
||||
|
||||
@@ -26,8 +26,8 @@ def nybb_polydf():
|
||||
@pytest.fixture
|
||||
def merged_shapes(nybb_polydf):
|
||||
# Merged geometry
|
||||
manhattan_bronx = nybb_polydf.loc[3:4,]
|
||||
others = nybb_polydf.loc[0:2,]
|
||||
manhattan_bronx = nybb_polydf.loc[3:4]
|
||||
others = nybb_polydf.loc[0:2]
|
||||
|
||||
collapsed = [others.geometry.unary_union, manhattan_bronx.geometry.unary_union]
|
||||
merged_shapes = GeoDataFrame(
|
||||
|
||||
@@ -23,14 +23,6 @@ from geopandas._compat import PANDAS_GE_024
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
not_yet_implemented = pytest.mark.skip(reason="Not yet implemented")
|
||||
no_sorting = pytest.mark.skip(reason="Sorting not supported")
|
||||
skip_pandas_below_024 = pytest.mark.skipif(
|
||||
not PANDAS_GE_024, reason="Sorting not supported"
|
||||
)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Compat with extension tests in older pandas versions
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -48,6 +40,13 @@ if not PANDAS_GE_024:
|
||||
extension_tests.BaseParsingTests = object
|
||||
|
||||
|
||||
not_yet_implemented = pytest.mark.skip(reason="Not yet implemented")
|
||||
no_sorting = pytest.mark.skip(reason="Sorting not supported")
|
||||
skip_pandas_below_024 = pytest.mark.skipif(
|
||||
not PANDAS_GE_024, reason="Sorting not supported"
|
||||
)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Required fixtures
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@ import shutil
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from shapely.geometry import Point, Polygon
|
||||
from shapely.geometry import Point
|
||||
import fiona
|
||||
|
||||
import geopandas
|
||||
@@ -24,9 +24,6 @@ from geopandas.testing import assert_geoseries_equal, assert_geodataframe_equal
|
||||
from geopandas.tests.util import connect, create_postgis, PACKAGE_DIR, validate_boro_df
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestDataFrame:
|
||||
def setup_method(self):
|
||||
N = 10
|
||||
@@ -207,7 +204,6 @@ class TestDataFrame:
|
||||
df.geometry = df
|
||||
|
||||
def test_rename_geometry(self):
|
||||
column_name = self.df.geometry.name
|
||||
assert self.df.geometry.name == "geometry"
|
||||
df2 = self.df.rename_geometry("new_name")
|
||||
assert df2.geometry.name == "new_name"
|
||||
|
||||
@@ -140,7 +140,7 @@ class TestSeries:
|
||||
Test whether GeoSeries.to_json works and returns an actual json file.
|
||||
"""
|
||||
json_str = self.g3.to_json()
|
||||
json_dict = json.loads(json_str)
|
||||
json.loads(json_str)
|
||||
# TODO : verify the output is a valid GeoJSON.
|
||||
|
||||
def test_representative_point(self):
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestMerging:
|
||||
# check metadata
|
||||
self._check_metadata(res)
|
||||
|
||||
## test that crs and other geometry name are preserved
|
||||
# test that crs and other geometry name are preserved
|
||||
self.gdf.crs = {"init": "epsg:4326"}
|
||||
self.gdf = self.gdf.rename(columns={"geometry": "points"}).set_geometry(
|
||||
"points"
|
||||
|
||||
@@ -7,7 +7,7 @@ from six import PY3, PY2
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import shapely
|
||||
from shapely.geometry import Point, Polygon
|
||||
from shapely.geometry import Point
|
||||
|
||||
from geopandas import GeoDataFrame, GeoSeries
|
||||
from geopandas.array import from_shapely
|
||||
|
||||
@@ -15,7 +15,7 @@ import pytest
|
||||
|
||||
matplotlib = pytest.importorskip("matplotlib")
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.pyplot as plt # noqa
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -428,10 +428,10 @@ class TestMapclassifyPlotting:
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
try:
|
||||
import mapclassify
|
||||
import mapclassify # noqa
|
||||
except ImportError:
|
||||
try:
|
||||
import pysal
|
||||
import pysal # noqa
|
||||
except ImportError:
|
||||
pytest.importorskip("mapclassify")
|
||||
pth = get_path("naturalearth_lowres")
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
from pandas import Series, DataFrame
|
||||
from shapely.geometry import Point
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import os.path
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
from geopandas import GeoDataFrame
|
||||
from geopandas.testing import (
|
||||
from geopandas.testing import ( # noqa
|
||||
geom_equals,
|
||||
geom_almost_equals,
|
||||
assert_geoseries_equal,
|
||||
) # flake8: noqa
|
||||
)
|
||||
from pandas import Series
|
||||
|
||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||
@@ -25,9 +24,9 @@ except ImportError:
|
||||
|
||||
# mock not used here, but the import from here is used in other modules
|
||||
try:
|
||||
import unittest.mock as mock
|
||||
import unittest.mock as mock # noqa
|
||||
except ImportError:
|
||||
import mock
|
||||
import mock # noqa
|
||||
|
||||
|
||||
def validate_boro_df(df, case_sensitive=False):
|
||||
@@ -78,7 +77,10 @@ def connect_spatialite():
|
||||
"""
|
||||
Return a memory-based SQLite3 connection with SpatiaLite enabled & initialized.
|
||||
|
||||
`The sqlite3 module must be built with loadable extension support <https://docs.python.org/3/library/sqlite3.html#f1>`_ and `SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/index>`_ must be available on the system as a SQLite module.
|
||||
`The sqlite3 module must be built with loadable extension support
|
||||
<https://docs.python.org/3/library/sqlite3.html#f1>`_ and
|
||||
`SpatiaLite <https://www.gaia-gis.it/fossil/libspatialite/index>`_
|
||||
must be available on the system as a SQLite module.
|
||||
Packages available on Anaconda meet requirements.
|
||||
|
||||
Exceptions
|
||||
|
||||
@@ -6,4 +6,11 @@ from .sjoin import sjoin
|
||||
from .util import collect
|
||||
from .crs import explicit_crs_from_epsg
|
||||
|
||||
__all__ = ["overlay", "sjoin", "geocode", "reverse_geocode", "collect"]
|
||||
__all__ = [
|
||||
"collect",
|
||||
"explicit_crs_from_epsg",
|
||||
"geocode",
|
||||
"overlay",
|
||||
"reverse_geocode",
|
||||
"sjoin",
|
||||
]
|
||||
|
||||
@@ -19,7 +19,8 @@ def explicit_crs_from_epsg(crs=None, epsg=None):
|
||||
epsg = epsg_from_crs(crs)
|
||||
if epsg is None:
|
||||
raise ValueError(
|
||||
"No epsg code provided or epsg code could not be identified from the provided crs."
|
||||
"No epsg code provided or epsg code could not be identified "
|
||||
"from the provided crs."
|
||||
)
|
||||
|
||||
_crs = re.search(r"\n<{}>\s*(.+?)\s*<>".format(epsg), get_epsg_file_contents())
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from shapely.geometry import Point, Polygon
|
||||
@@ -15,7 +13,7 @@ from pandas.util.testing import assert_frame_equal
|
||||
|
||||
|
||||
pandas_0_18_problem = (
|
||||
"fails under pandas < 0.19 due to pandas issue 15692," "not problem with sjoin."
|
||||
"fails under pandas < 0.19 due to pandas issue 15692, not problem with sjoin."
|
||||
)
|
||||
|
||||
|
||||
@@ -144,10 +142,10 @@ class TestSpatialJoin:
|
||||
index, df1, df2, expected = dfs
|
||||
|
||||
with pytest.raises(ValueError, match="'left_df' should be GeoDataFrame"):
|
||||
res = sjoin(df1.geometry, df2)
|
||||
sjoin(df1.geometry, df2)
|
||||
|
||||
with pytest.raises(ValueError, match="'right_df' should be GeoDataFrame"):
|
||||
res = sjoin(df1, df2.geometry)
|
||||
sjoin(df1, df2.geometry)
|
||||
|
||||
@pytest.mark.parametrize("dfs", ["default-index", "string-index"], indirect=True)
|
||||
@pytest.mark.parametrize("op", ["intersects", "contains", "within"])
|
||||
@@ -247,9 +245,9 @@ class TestSpatialJoinNYBB:
|
||||
# original index names should be unchanged
|
||||
pointdf2 = self.pointdf.copy()
|
||||
pointdf2.index.name = "pointid"
|
||||
df = sjoin(pointdf2, self.polydf, how=how)
|
||||
sjoin(pointdf2, self.polydf, how=how)
|
||||
assert pointdf2.index.name == "pointid"
|
||||
assert self.polydf.index.name == None
|
||||
assert self.polydf.index.name is None
|
||||
|
||||
def test_sjoin_values(self):
|
||||
# GH190
|
||||
|
||||
Reference in New Issue
Block a user