Skip to content

filter cli command outputs a valid empty filter if all subfilters are removed. #654

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

Merged
merged 1 commit into from
Sep 22, 2022
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
8 changes: 2 additions & 6 deletions planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,8 @@ def filter(ctx,
else:
filters.append(f)

if filters:
if len(filters) > 1:
filt = data_filter.and_filter(filters)
else:
filt = filters[0]
echo_json(filt, pretty)
filt = data_filter.and_filter(filters)
echo_json(filt, pretty)


@data.command()
Expand Down
31 changes: 31 additions & 0 deletions planet/clients/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ async def search(self,
`name` parameter of the search defaults to the id of the generated
search id if `name` is not specified.

To filter to items you have access to download which are of standard
(aka not test) quality, use the following:

```python
>>> from planet import data_filter
>>> data_filter.and_filter([
... data_filter.permission_filter(),
... data_filter.std_quality_filter()
>>> ])

```

To avoid filtering out any imagery, supply a blank AndFilter, which can
be created with `data_filter.and_filter([])`.

Example:

```python
Expand Down Expand Up @@ -176,6 +191,22 @@ async def create_search(self,
enable_email: bool = False) -> dict:
"""Create a new saved structured item search.

To filter to items you have access to download which are of standard
(aka not test) quality, use the following:

```python
>>> from planet import data_filter
>>> data_filter.and_filter([
... data_filter.permission_filter(),
... data_filter.std_quality_filter()
>>> ])

```

To avoid filtering out any imagery, supply a blank AndFilter, which can
be created with `data_filter.and_filter([])`.


Parameters:
name: The name of the saved search.
item_types: The item types to include in the search.
Expand Down
9 changes: 2 additions & 7 deletions tests/integration/test_data_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,8 @@ def test_data_filter_defaults(permission,
assert result.exit_code == 0

[default_filters.remove(rem) for rem in [p_remove, s_remove] if rem]
if len(default_filters) > 1:
expected_filt = {"type": "AndFilter", "config": default_filters}
assert_and_filters_equal(json.loads(result.output), expected_filt)
elif len(default_filters) == 1:
assert json.loads(result.output) == default_filters[0]
else:
assert result.output == ''
expected_filt = {"type": "AndFilter", "config": default_filters}
assert_and_filters_equal(json.loads(result.output), expected_filt)


@respx.mock
Expand Down