Skip to content

Commit

Permalink
Resolved: coords are not matched in 2 variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabhicusp committed Jan 18, 2024
1 parent f7d23e0 commit 501c8c7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions xql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def apply_order_by(fields: t.List[str], ds: xr.Dataset) -> xr.Dataset:
return ordered_ds


def apply_group_by(time_fields: t.List[str], ds: xr.Dataset, agg_funcs: t.Dict[str, str], dim: t.List[str] = []) -> xr.Dataset:
def apply_group_by(time_fields: t.List[str], ds: xr.Dataset, agg_funcs: t.Dict[str, str],
dim: t.List[str] = []) -> xr.Dataset:
"""
Apply group-by and aggregation operations to the dataset based on specified fields and aggregation functions.
Expand Down Expand Up @@ -183,11 +184,11 @@ def apply_group_by(time_fields: t.List[str], ds: xr.Dataset, agg_funcs: t.Dict[s
groups = grouped_ds.groupby(grouped_ds['time'].dt.strftime(timestamp_formats[time_fields[0]]))
grouped_ds = apply_aggregation(groups, agg_func['func'], None)
grouped_ds = grouped_ds.rename({"strftime" : time_fields[0]})
dim = [value for value in dim if value in grouped_ds[agg_func['var']].coords]
grouped_ds = apply_aggregation(grouped_ds, agg_func['func'], dim)
grouped_ds = grouped_ds.rename({agg_func['var'] : f"{agg_func['func']}_{agg_func['var']}"})
agg_datasets.append(grouped_ds)
grouped_ds = xr.merge(agg_datasets)


return grouped_ds

Expand Down Expand Up @@ -303,6 +304,7 @@ def parse_query(query: str) -> xr.Dataset:
agg_datasets = []
for agg_func in agg_funcs:
key, value = agg_func['var'], agg_func['func']
coord_to_squeeze = [value for value in coord_to_squeeze if value in ds[key].coords]
agg_result = apply_aggregation(ds[[key]], value, coord_to_squeeze)
agg_result = agg_result.rename({key : f'{value}_{key}'})
agg_datasets.append(agg_result)
Expand Down

0 comments on commit 501c8c7

Please sign in to comment.