Skip to content

Commit

Permalink
Convert self.dim to a str to fix mypy warnings
Browse files Browse the repository at this point in the history
- Remove unused type ignore comments
  • Loading branch information
tomvothecoder committed Sep 23, 2024
1 parent e9c000e commit 9669dfc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions xcdat/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def _averager(
# it becomes obsolete after the data variable is averaged. When the
# averaged data variable is added to the dataset, the new time dimension
# and its associated coordinates are also added.
ds = ds.drop_dims(self.dim) # type: ignore
ds = ds.drop_dims(self.dim)
ds[dv_avg.name] = dv_avg

if keep_weights:
Expand Down Expand Up @@ -847,7 +847,7 @@ def _set_data_var_attrs(self, data_var: str):
dv = _get_data_var(self._dataset, data_var)

self.data_var = data_var
self.dim = get_dim_coords(dv, "T").name
self.dim = str(get_dim_coords(dv, "T").name)

if not _contains_datetime_like_objects(dv[self.dim]):
first_time_coord = dv[self.dim].values[0]
Expand Down Expand Up @@ -1119,9 +1119,7 @@ def _drop_leap_days(self, ds: xr.Dataset):
-------
xr.Dataset
"""
ds = ds.sel( # type: ignore
**{self.dim: ~((ds.time.dt.month == 2) & (ds.time.dt.day == 29))}
)
ds = ds.sel(**{self.dim: ~((ds.time.dt.month == 2) & (ds.time.dt.day == 29))})
return ds

def _average(self, ds: xr.Dataset, data_var: str) -> xr.DataArray:
Expand All @@ -1146,9 +1144,9 @@ def _average(self, ds: xr.Dataset, data_var: str) -> xr.DataArray:
time_bounds = ds.bounds.get_bounds("T", var_key=data_var)
self._weights = self._get_weights(time_bounds)

dv = dv.weighted(self._weights).mean(dim=self.dim) # type: ignore
dv = dv.weighted(self._weights).mean(dim=self.dim)
else:
dv = dv.mean(dim=self.dim) # type: ignore
dv = dv.mean(dim=self.dim)

dv = self._add_operation_attrs(dv)

Expand Down

0 comments on commit 9669dfc

Please sign in to comment.