Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Changed order and names of new data_frame_subset() operation inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Sep 25, 2018
1 parent a375865 commit f4b55d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Version 2.0.0.dev20 (in development)

* Changed order and names of new `data_frame_subset` operation inputs.
* Improved scatter plot [#763](https://github.com/CCI-Tools/cate/issues/763).
We can now plot N-D arrays. Plot types are "Point", "Hexbin", and "2D Histogram".
* Fixed problem where workspace save-as sometimes fails on Windows [#764](https://github.com/CCI-Tools/cate/issues/764)
Expand Down
16 changes: 8 additions & 8 deletions cate/ops/data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,20 @@ def _within(geometry: GeometryLike):

@op(tags=['filter'], version='1.0')
@op_input('gdf', data_type=DataFrameLike)
@op_input('var_names', value_set_source='gdf', data_type=VarNamesLike)
@op_input('region_op', data_type=str, value_set=REGION_MODES)
@op_input('region', data_type=PolygonLike)
@op_input('geom_op', data_type=str, value_set=REGION_MODES)
@op_input('var_names', value_set_source='gdf', data_type=VarNamesLike)
def data_frame_subset(gdf: gpd.GeoDataFrame,
var_names: VarNamesLike.TYPE = None,
region_op: bool = 'intersects',
region: PolygonLike.TYPE = None,
geom_op: bool = 'intersects') -> gpd.GeoDataFrame:
var_names: VarNamesLike.TYPE = None) -> gpd.GeoDataFrame:
"""
Create a GeoDataFrame subset from given variables (data frame columns) and/or region.
:param gdf: A GeoDataFrame.
:param var_names: The variables (columns) to select.
:param region_op: The geometric operation to be performed if *region* is given.
:param region: A region polygon used to filter rows.
:param geom_op: The geometric operation to be performed if *region* is given.
:param var_names: The variables (columns) to select.
:return: A GeoDataFrame subset.
"""

Expand All @@ -209,9 +209,9 @@ def data_frame_subset(gdf: gpd.GeoDataFrame,
var_names = ['geometry'] + var_names
gdf = gdf[var_names]

if region and geom_op:
if region and region_op:
geom_str = PolygonLike.format(region)
gdf = data_frame_query(gdf, f'@{geom_op}("{geom_str}")')
gdf = data_frame_query(gdf, f'@{region_op}("{geom_str}")')

return gdf

Expand Down

0 comments on commit f4b55d6

Please sign in to comment.