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

prevent accessing each var again when looping over dataset vars #286

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
2 changes: 1 addition & 1 deletion xugrid/core/dataarray_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def to_geodataframe(
else:
ds = self.obj.to_dataset()

variables = [var for var in ds.data_vars if dim in ds[var].dims]
variables = [var for var in ds.data_vars if dim in ds.variables[var].dims]
# TODO deal with time-dependent data, etc.
# Basically requires checking which variables are static, which aren't.
# For non-static, requires repeating all geometries.
Expand Down
2 changes: 1 addition & 1 deletion xugrid/core/dataset_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def to_geodataframe(self, dim_order=None) -> "geopandas.GeoDataFrame": # type:
else:
raise ValueError("invalid topology dimension on grid")

variables = [var for var in ds.data_vars if dim in ds[var].dims]
variables = [var for var in ds.data_vars if dim in ds.variables[var].dims]
if variables:
data = ds[variables].to_dataframe(dim_order=dim_order)
else:
Expand Down
6 changes: 5 additions & 1 deletion xugrid/ugrid/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def default_topology_attrs(name: str, topology_dimension: int):


def _get_topology(ds: xr.Dataset) -> List[str]:
return [k for k in ds.data_vars if ds[k].attrs.get("cf_role") == "mesh_topology"]
return [
var
for var in ds.data_vars
if ds.variables[var].attrs.get("cf_role") == "mesh_topology"
]


def _infer_xy_coords(
Expand Down
2 changes: 1 addition & 1 deletion xugrid/ugrid/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def validate_partition_objects(
unique_vars = set(chain(*allvars))
# Check dimensions
dims_per_var = [
{ds[var].dims for ds in data_objects if var in ds.data_vars}
{ds.variables[var].dims for ds in data_objects if var in ds.data_vars}
for var in unique_vars
]
for var, vardims in zip(unique_vars, dims_per_var):
Expand Down
Loading