Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code maintenance #628

Merged
merged 9 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# This is the configuration for pre-commit, a local framework for managing pre-commit hooks
# Check out the docs at: https://pre-commit.com/

exclude: (\.min\.js$|\.svg$|\.html$)
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
Expand All @@ -13,16 +14,15 @@ repos:
- id: check-toml
- id: detect-private-key
- id: end-of-file-fixer
exclude: (\.min\.js$|\.svg$)
- id: trailing-whitespace
exclude: \.svg$
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.263
hooks:
- id: flake8 # See 'setup.cfg' for args
- id: ruff
args: [geoviews]
files: geoviews/
- repo: https://github.com/hoxbro/clean_notebook
rev: 0.1.5
rev: v0.1.9
hooks:
- id: clean-notebook
6 changes: 1 addition & 5 deletions geoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
Cycle, Palette, Overlay, Layout, NdOverlay, NdLayout,
HoloMap, DynamicMap, GridSpace, Dimension, dim)

try:
# Only available in HoloViews >=1.11
from holoviews import render, save # noqa (API import)
except:
pass
from holoviews import render, save # noqa (API import)

from .annotators import annotate # noqa (API import)
from .element import ( # noqa (API import)
Expand Down
2 changes: 1 addition & 1 deletion geoviews/annotators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from holoviews.annotators import (
annotate, Annotator, PathAnnotator, PolyAnnotator, PointAnnotator,
RectangleAnnotator # noqa
RectangleAnnotator
)
from holoviews.plotting.links import DataLink, VertexTableLink as hvVertexTableLink
from panel.util import param_name
Expand Down
2 changes: 0 additions & 2 deletions geoviews/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from .geom_dict import GeomDictInterface # noqa (API import)
from .geopandas import GeoPandasInterface # noqa (API import)
from .iris import CubeInterface # noqa (API import)
18 changes: 10 additions & 8 deletions geoviews/data/geom_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from holoviews.core.data import Interface, DictInterface, MultiInterface
from holoviews.core.data.interface import DataError
from holoviews.core.data.spatialpandas import to_geom_dict
from holoviews.core.dimension import OrderedDict as cyODict, dimension_name
from holoviews.core.dimension import dimension_name
from holoviews.core.util import isscalar

from ..util import asarray, geom_types, geom_to_array, geom_length
Expand All @@ -25,7 +25,7 @@ def applies(cls, obj):

@classmethod
def init(cls, eltype, data, kdims, vdims):
odict_types = (OrderedDict, cyODict)
odict_types = (OrderedDict,)
if kdims is None:
kdims = eltype.kdims
if vdims is None:
Expand Down Expand Up @@ -245,9 +245,10 @@ def shape_mask(cls, dataset, selection):
elif isinstance(xsel, tuple):
x0, x1 = xsel
else:
raise ValueError("Only slicing is supported on geometries, %s "
"selection is of type %s."
% (xdim, type(xsel).__name__))
raise ValueError(
f"Only slicing is supported on geometries, {xdim} "
f"selection is of type {type(xsel).__name__}."
)

if ysel is None:
y0, y1 = cls.range(dataset, ydim)
Expand All @@ -256,9 +257,10 @@ def shape_mask(cls, dataset, selection):
elif isinstance(ysel, tuple):
y0, y1 = ysel
else:
raise ValueError("Only slicing is supported on geometries, %s "
"selection is of type %s."
% (ydim, type(ysel).__name__))
raise ValueError(
f"Only slicing is supported on geometries, {ydim} "
f"selection is of type {type(ysel).__name__}."
)

bounds = box(x0, y0, x1, y1)
geom = dataset.data['geometry']
Expand Down
18 changes: 9 additions & 9 deletions geoviews/data/geopandas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import sys
import warnings

Expand Down Expand Up @@ -98,7 +96,7 @@ def init(cls, eltype, data, kdims, vdims):

try:
shp_types = {gt[5:] if 'Multi' in gt else gt for gt in data.geom_type}
except:
except Exception:
shp_types = []
if len(shp_types) > 1:
raise DataError('The GeopandasInterface can only read dataframes which '
Expand Down Expand Up @@ -191,9 +189,10 @@ def shape_mask(cls, dataset, selection):
elif isinstance(xsel, tuple):
x0, x1 = xsel
else:
raise ValueError("Only slicing is supported on geometries, %s "
"selection is of type %s."
% (xdim, type(xsel).__name__))
raise ValueError(
f"Only slicing is supported on geometries, {xdim} "
f"selection is of type {type(xsel).__name__}."
)

if ysel is None:
y0, y1 = cls.range(dataset, ydim)
Expand All @@ -202,9 +201,10 @@ def shape_mask(cls, dataset, selection):
elif isinstance(ysel, tuple):
y0, y1 = ysel
else:
raise ValueError("Only slicing is supported on geometries, %s "
"selection is of type %s."
% (ydim, type(ysel).__name__))
raise ValueError(
f"Only slicing is supported on geometries, {ydim} "
f"selection is of type {type(ysel).__name__}."
)

bounds = box(x0, y0, x1, y1)
col = cls.geo_column(dataset.data)
Expand Down
4 changes: 1 addition & 3 deletions geoviews/data/iris.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import sys
import datetime
from itertools import product
Expand Down Expand Up @@ -116,7 +114,7 @@ def init(cls, eltype, data, kdims, vdims):
try:
data = iris.cube.Cube(value_array, long_name=vdim.name,
dim_coords_and_dims=coords)
except:
except Exception:
pass
if not isinstance(data, iris.cube.Cube):
raise TypeError('Data must be be an iris Cube type.')
Expand Down
2 changes: 1 addition & 1 deletion geoviews/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __call__(self, *args, **kwargs):
else:
args = (Dataset,)
kwargs['kdims'] = []
converted = super(GeoConversion, self).__call__(*args, **kwargs)
converted = super().__call__(*args, **kwargs)
if is_gpd:
if kdims is None: kdims = group_type.kdims
converted = converted.map(lambda x: x.clone(kdims=kdims, new_type=group_type), Dataset)
Expand Down
2 changes: 1 addition & 1 deletion geoviews/element/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Comparison(HvComparison):

@classmethod
def register(cls):
super(Comparison, cls).register()
super().register()
cls.equality_type_funcs[Image] = cls.compare_dataset
cls.equality_type_funcs[Points] = cls.compare_dataset
cls.equality_type_funcs[LineContours] = cls.compare_dataset
Expand Down
66 changes: 34 additions & 32 deletions geoviews/element/geo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import param
import numpy as np

from bokeh.models import MercatorTileSource
from cartopy import crs as ccrs
from cartopy.feature import Feature as cFeature
from cartopy.io.img_tiles import GoogleTiles
Expand Down Expand Up @@ -29,14 +30,11 @@
except ImportError:
Cube = None

try:
from bokeh.models import MercatorTileSource
except:
MercatorTileSource = None


try:
from owslib.wmts import WebMapTileService
except:
except ImportError:
WebMapTileService = None

from ..util import (
Expand Down Expand Up @@ -107,14 +105,14 @@ def __init__(self, data, kdims=None, vdims=None, **kwargs):
kwargs['crs'] = crs
elif isinstance(data, _Element):
kwargs['crs'] = data.crs
super(_Element, self).__init__(data, kdims=kdims, vdims=vdims, **kwargs)
super().__init__(data, kdims=kdims, vdims=vdims, **kwargs)


def clone(self, data=None, shared_data=True, new_type=None,
*args, **overrides):
if 'crs' not in overrides and (not new_type or isinstance(new_type, _Element)):
overrides['crs'] = self.crs
return super(_Element, self).clone(data, shared_data, new_type,
return super().clone(data, shared_data, new_type,
*args, **overrides)


Expand Down Expand Up @@ -144,7 +142,7 @@ def __init__(self, data, kdims=None, vdims=None, **params):
if not isinstance(data, cFeature):
raise TypeError('%s data has to be an cartopy Feature type'
% type(data).__name__)
super(Feature, self).__init__(data, kdims=kdims, vdims=vdims, **params)
super().__init__(data, kdims=kdims, vdims=vdims, **params)

def __call__(self, *args, **kwargs):
return self.clone().opts(*args, **kwargs)
Expand Down Expand Up @@ -203,7 +201,7 @@ def range(self, dim, data_range=True, dimension_range=True):
return util.dimension_range(lower, upper, dim.range, dim.soft_range)
else:
return lower, upper
return super(Feature, self).range(dim, data_range, dimension_range)
return super().range(dim, data_range, dimension_range)


class WMTS(_GeoFeature):
Expand All @@ -230,9 +228,11 @@ def __init__(self, data, kdims=None, vdims=None, **params):
elif WebMapTileService and isinstance(data, WebMapTileService):
pass
elif not isinstance(data, str):
raise TypeError('%s data should be a tile service URL not a %s type.'
% (type(self).__name__, type(data).__name__) )
super(WMTS, self).__init__(data, kdims=kdims, vdims=vdims, **params)
raise TypeError(
f'{type(self).__name__} data should be a tile service '
f'URL not a {type(data).__name__} type.'
)
super().__init__(data, kdims=kdims, vdims=vdims, **params)

def __call__(self, *args, **kwargs):
return self.opts(*args, **kwargs)
Expand Down Expand Up @@ -382,7 +382,7 @@ def from_xarray(cls, da, crs=None, apply_transform=False,
return from_xarray(da, crs, apply_transform, **kwargs)

def trimesh(self):
trimesh = super(QuadMesh, self).trimesh()
trimesh = super().trimesh()
node_params = util.get_param_values(trimesh.nodes)
node_params['crs'] = self.crs
nodes = TriMesh.node_type(trimesh.nodes.data, **node_params)
Expand Down Expand Up @@ -580,22 +580,23 @@ def __init__(self, data, kdims=None, vdims=None, **params):
if 'crs' in params:
crs = params['crs']
mismatch = None
if nodes is not None and type(crs) != type(nodes.crs):
if nodes is not None and type(crs) != type(nodes.crs): # noqa: E721
mismatch = 'nodes'
elif edges is not None and type(crs) != type(edges.crs):
elif edges is not None and type(crs) != type(edges.crs): # noqa: E721
mismatch = 'edges'
if mismatch:
raise ValueError("Coordinate reference system supplied "
"to %s element must match the crs of "
"the %s. Expected %s found %s." %
(mismatch, type(self).__name__, nodes.crs, crs))
raise ValueError(
"Coordinate reference system supplied "
f"to {mismatch} element must match the crs of "
f"the {type(self).__name__}. Expected {nodes.crs} found {crs}."
)
elif nodes is not None:
crs = nodes.crs
params['crs'] = crs
else:
crs = self.crs

super(Graph, self).__init__(data, kdims, vdims, **params)
super().__init__(data, kdims, vdims, **params)
self.nodes.crs = crs


Expand All @@ -605,7 +606,7 @@ def edgepaths(self):
Returns the fixed EdgePaths or computes direct connections
between supplied nodes.
"""
edgepaths = super(Graph, self).edgepaths
edgepaths = super().edgepaths
edgepaths.crs = self.crs
return edgepaths

Expand All @@ -632,22 +633,23 @@ def __init__(self, data, kdims=None, vdims=None, **params):
if 'crs' in params:
crs = params['crs']
mismatch = None
if nodes is not None and type(crs) != type(nodes.crs):
if nodes is not None and type(crs) != type(nodes.crs): # noqa: E721
mismatch = 'nodes'
elif edges is not None and type(crs) != type(edges.crs):
elif edges is not None and type(crs) != type(edges.crs): # noqa: E721
mismatch = 'edges'
if mismatch:
raise ValueError("Coordinate reference system supplied "
"to %s element must match the crs of "
"the %s. Expected %s found %s." %
(mismatch, type(self).__name__, nodes.crs, crs))
raise ValueError(
"Coordinate reference system supplied "
f"to {mismatch} element must match the crs of "
f"the {type(self).__name__}. Expected {nodes.crs} found {crs}."
)
elif nodes is not None:
crs = nodes.crs
params['crs'] = crs
else:
crs = self.crs

super(TriMesh, self).__init__(data, kdims, vdims, **params)
super().__init__(data, kdims, vdims, **params)
self.nodes.crs = crs

@property
Expand All @@ -656,7 +658,7 @@ def edgepaths(self):
Returns the fixed EdgePaths or computes direct connections
between supplied nodes.
"""
edgepaths = super(TriMesh, self).edgepaths
edgepaths = super().edgepaths
edgepaths.crs = self.crs
return edgepaths

Expand Down Expand Up @@ -833,7 +835,7 @@ def __init__(self, data, kdims=None, vdims=None, **params):
'provide the value as part of a dictionary of '
'the form {\'geometry\': <shapely.Geometry>, '
'\'level\': %s} instead' % params['level'])
super(Shape, self).__init__(data, kdims=kdims, vdims=vdims, **params)
super().__init__(data, kdims=kdims, vdims=vdims, **params)


@classmethod
Expand Down Expand Up @@ -941,8 +943,8 @@ def from_records(cls, records, dataset=None, on=None, value=None,
vdims = dataset.vdims
ddims = dataset.dimensions()
if None in vdims:
raise ValueError('Value dimension %s not found '
'in dataset dimensions %s' % (value, ddims) )
raise ValueError('Value dimension {} not found '
'in dataset dimensions {}'.format(value, ddims) )
else:
vdims = []

Expand Down
Loading