Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 6, 2023
1 parent 9e08940 commit d4c2738
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cf_xarray/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def cf_to_lines(ds: xr.Dataset):
It has the same dimension as the ``part_node_count`` or the coordinates variables, or
``'features'`` if those were not present in ``ds``.
"""
from shapely import from_ragged_array, GeometryType
from shapely import GeometryType, from_ragged_array

# Shorthand for convenience
geo = ds.geometry_container.attrs
Expand Down Expand Up @@ -419,15 +419,19 @@ def cf_to_lines(ds: xr.Dataset):
part_node_count = xr.DataArray([1] * xy.shape[0], dims=(feat_dim,))
if feat_dim in ds.coords:
part_node_count = part_node_count.assign_coords({feat_dim: ds[feat_dim]})

Check warning on line 421 in cf_xarray/geometry.py

View check run for this annotation

Codecov / codecov/patch

cf_xarray/geometry.py#L418-L421

Added lines #L418 - L421 were not covered by tests

geoms = lines

Check warning on line 423 in cf_xarray/geometry.py

View check run for this annotation

Codecov / codecov/patch

cf_xarray/geometry.py#L423

Added line #L423 was not covered by tests
else:
part_node_count = ds[part_node_count_name]

# get index of offset1 values that are edges for part_node_count
offset2 = np.nonzero(np.isin(offset1, np.insert(np.cumsum(part_node_count), 0, 0)))[0]
multilines = from_ragged_array(GeometryType.MULTILINESTRING, xy, offsets=(offset1, offset2))

offset2 = np.nonzero(
np.isin(offset1, np.insert(np.cumsum(part_node_count), 0, 0))
)[0]
multilines = from_ragged_array(
GeometryType.MULTILINESTRING, xy, offsets=(offset1, offset2)
)

# get items from lines or multilines depending on number of segments
geoms = np.where(np.diff(offset2) == 1, lines[offset2[:-1]], multilines)

Expand Down

0 comments on commit d4c2738

Please sign in to comment.