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

Update pre-commit and add sorting of imports #731

Merged
merged 9 commits into from
Jun 21, 2024
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude: (\.min\.js$|\.svg$|\.html$)
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -20,16 +20,16 @@ repos:
- id: check-json
- id: detect-private-key
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.4.9
hooks:
- id: ruff
files: geoviews/
- repo: https://github.com/hoxbro/clean_notebook
rev: v0.1.14
rev: v0.1.15
hooks:
- id: clean-notebook
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
Expand Down
151 changes: 128 additions & 23 deletions geoviews/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,142 @@
import param
from functools import partial

from holoviews import (extension, help, opts, output, renderer, Store, # noqa (API import)
Cycle, Palette, Overlay, Layout, NdOverlay, NdLayout,
HoloMap, DynamicMap, GridSpace, Dimension, dim)
import param
from holoviews import (
Cycle,
Dimension,
DynamicMap,
GridSpace,
HoloMap,
Layout,
NdLayout,
NdOverlay,
Overlay,
Palette,
Store,
dim,
extension,
help,
opts,
output,
render,
renderer,
save,
)

from holoviews import render, save # noqa (API import)
from . import (
data,
feature,
plotting,
tile_sources,
)
from ._warnings import GeoviewsDeprecationWarning, GeoviewsUserWarning
from .element import (
RGB,
WMTS,
Contours,
Dataset,
EdgePaths,
Feature,
FilledContours,
Graph,
HexTiles,
Image,
ImageStack,
Labels,
LineContours,
Nodes,
Path,
Points,
Polygons,
QuadMesh,
Rectangles,
Segments,
Shape,
Text,
Tiles,
TriMesh,
VectorField,
WindBarbs,
)
from .util import from_xarray

from .element import ( # noqa (API import)
_Element, Feature, Tiles, WMTS, LineContours, FilledContours,
Text, Image, ImageStack, Points, Path, Polygons, Shape, Dataset, RGB,
Contours, Graph, TriMesh, Nodes, EdgePaths, QuadMesh, VectorField,
HexTiles, Labels, Rectangles, Segments, WindBarbs
__version__ = str(
param.version.Version(
fpath=__file__, archive_commit="$Format:%h$", reponame="geoviews"
)
)
from .util import from_xarray # noqa (API import)
from ._warnings import GeoviewsDeprecationWarning, GeoviewsUserWarning # noqa: F401
from . import data # noqa (API import)
from . import plotting # noqa (API import)
from . import feature # noqa (API import)
from . import tile_sources # noqa (API import)

__version__ = str(param.version.Version(fpath=__file__, archive_commit="$Format:%h$",
reponame="geoviews"))
__all__ = (
"Contours",
"Cycle",
"Dataset",
"Dimension",
"DynamicMap",
"EdgePaths",
"Feature",
"FilledContours",
"GeoviewsDeprecationWarning",
"GeoviewsUserWarning",
"Graph",
"GridSpace",
"HexTiles",
"HoloMap",
"Image",
"ImageStack",
"Labels",
"Layout",
"LineContours",
"NdLayout",
"NdOverlay",
"Nodes",
"Overlay",
"Palette",
"Path",
"Points",
"Polygons",
"QuadMesh",
"RGB",
"Rectangles",
"Segments",
"Shape",
"Store",
"Text",
"Tiles",
"TriMesh",
"VectorField",
"WMTS",
"WindBarbs",
"__version__",
"data",
"dim",
"extension",
"feature",
"from_xarray",
"help",
"opts",
"output",
"plotting",
"render",
"renderer",
"save",
"tile_sources",
# Lazy modules
"annotate",
"project",
"operation",
)

# Ensure opts utility is initialized with GeoViews elements
if Store._options:
Store.set_current_backend(Store.current_backend)

# make pyct's example/data commands available if possible
from functools import partial
try:
from pyct.cmd import copy_examples as _copy, fetch_data as _fetch, examples as _examples
from pyct.cmd import (
copy_examples as _copy,
examples as _examples,
fetch_data as _fetch,
)
copy_examples = partial(_copy, 'geoviews')
fetch_data = partial(_fetch, 'geoviews')
examples = partial(_examples, 'geoviews')
Expand All @@ -54,15 +161,13 @@ def __getattr__(attr):
return operation
raise AttributeError(f"module {__name__} has no attribute {attr!r}")

__all__ = [k for k in locals() if not k.startswith('_')]
__all__ += ['annotate', 'project', 'operation', '__version__']

def __dir__():
return __all__

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from . import operation
from .annotators import annotate
from .operation import project
from . import operation
1 change: 1 addition & 0 deletions geoviews/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def main(args=None):
import pyct.cmd
except ImportError:
import sys

from . import _missing_cmd
print(_missing_cmd())
sys.exit(1)
Expand Down
1 change: 0 additions & 1 deletion geoviews/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import holoviews as hv
import param

from packaging.version import Version

__all__ = (
Expand Down
25 changes: 16 additions & 9 deletions geoviews/annotators.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import param

import cartopy.crs as ccrs

import param
from holoviews.annotators import (
annotate, Annotator, PathAnnotator, PolyAnnotator, PointAnnotator,
RectangleAnnotator
Annotator,
PathAnnotator,
PointAnnotator,
PolyAnnotator,
RectangleAnnotator,
annotate,
)
from holoviews.plotting.links import DataLink, VertexTableLink as hvVertexTableLink
from panel.util import param_name

from .element import Path
from .models.custom_tools import CheckpointTool, RestoreTool, ClearTool
from .links import VertexTableLink, PointTableLink, HvRectanglesTableLink, RectanglesTableLink
from .links import (
HvRectanglesTableLink,
PointTableLink,
RectanglesTableLink,
VertexTableLink,
)
from .models.custom_tools import CheckpointTool, ClearTool, RestoreTool
from .operation import project
from .streams import PolyVertexDraw, PolyVertexEdit

Expand Down Expand Up @@ -74,12 +81,12 @@ def _init_stream(self):
style_kwargs = dict(node_style=self.node_style, feature_style=self.feature_style)
self._stream = PolyVertexDraw(
source=self.plot, data={}, num_objects=self.num_objects,
show_vertices=self.show_vertices, tooltip='%s Tool' % name,
show_vertices=self.show_vertices, tooltip=f'{name} Tool',
**style_kwargs
)
if self.edit_vertices:
self._vertex_stream = PolyVertexEdit(
source=self.plot, tooltip='%s Edit Tool' % name,
source=self.plot, tooltip=f'{name} Edit Tool',
**style_kwargs
)

Expand Down
8 changes: 5 additions & 3 deletions geoviews/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .geom_dict import GeomDictInterface # noqa (API import)
from .geopandas import GeoPandasInterface # noqa (API import)
from .iris import CubeInterface # noqa (API import)
from .geom_dict import GeomDictInterface
from .geopandas import GeoPandasInterface
from .iris import CubeInterface

__all__ = ("GeomDictInterface", "GeoPandasInterface", "CubeInterface")
34 changes: 24 additions & 10 deletions geoviews/data/geom_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from collections import OrderedDict

import numpy as np
from holoviews.core.data import Interface, DictInterface, MultiInterface
from holoviews.core.data import DictInterface, Interface, MultiInterface
from holoviews.core.data.interface import DataError
from holoviews.core.data.spatialpandas import to_geom_dict
from holoviews.core.dimension import dimension_name
from holoviews.core.util import isscalar

from ..util import asarray, geom_types, geom_to_array, geom_length
from ..util import asarray, geom_length, geom_to_array, geom_types


class GeomDictInterface(DictInterface):
Expand Down Expand Up @@ -37,8 +37,13 @@ def init(cls, eltype, data, kdims, vdims):
elif not isinstance(data, dict) or 'geometry' not in data:
xdim, ydim = kdims[:2]
from shapely.geometry import (
Point, LineString, Polygon, MultiPoint, MultiPolygon,
MultiLineString, LinearRing
LinearRing,
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
data = to_geom_dict(eltype, data, kdims, vdims, GeomDictInterface)
geom = data.get('geom_type') or MultiInterface.geom_type(eltype)
Expand Down Expand Up @@ -102,9 +107,9 @@ def validate(cls, dataset, validate_vdims):
elif 'geometry' not in dataset.data:
raise DataError("Could not find a 'geometry' column in the data.")
elif not isinstance(dataset.data['geometry'], BaseGeometry):
data_type = type(dataset.data['geometry']).__name__
raise DataError("The 'geometry' column should be a shapely"
"geometry type, found %s type instead." %
type(dataset.data['geometry']).__name__)
f"geometry type, found {data_type} type instead.")

@classmethod
def shape(cls, dataset):
Expand All @@ -113,7 +118,11 @@ def shape(cls, dataset):
@classmethod
def geom_type(cls, dataset):
from shapely.geometry import (
Polygon, MultiPolygon, LineString, MultiLineString, LinearRing
LinearRing,
LineString,
MultiLineString,
MultiPolygon,
Polygon,
)
geom = dataset.data['geometry']
if isinstance(geom, (Polygon, MultiPolygon)):
Expand All @@ -131,7 +140,7 @@ def geo_column(cls, dataset):

@classmethod
def has_holes(cls, dataset):
from shapely.geometry import Polygon, MultiPolygon
from shapely.geometry import MultiPolygon, Polygon
geom = dataset.data['geometry']
if isinstance(geom, Polygon) and geom.interiors:
return True
Expand All @@ -143,7 +152,7 @@ def has_holes(cls, dataset):

@classmethod
def holes(cls, dataset):
from shapely.geometry import Polygon, MultiPolygon
from shapely.geometry import MultiPolygon, Polygon
geom = dataset.data['geometry']
if isinstance(geom, Polygon):
return [[[geom_to_array(h) for h in geom.interiors]]]
Expand Down Expand Up @@ -301,7 +310,12 @@ def concat(cls, datasets, dimensions, vdims):

def geom_from_dict(geom, xdim, ydim, single_type, multi_type):
from shapely.geometry import (
Point, LineString, Polygon, MultiPoint, MultiPolygon, MultiLineString
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
if (xdim, ydim) in geom:
xs, ys = asarray(geom.pop((xdim, ydim))).T
Expand Down
Loading
Loading