Repository: opendatacube/datacube-core

Issue:
Ambiguous boolean check in `query_geopolygon`
Failure report from NCI install:

```
/g/data/v10/public/modules/agdc-py3/1.5.4/lib/python3.6/site-packages/datacube/api/query.py in query_geopolygon(geopolygon, **kwargs)
    172         raise ValueError('Spatial dimensions must be in the same coordinate reference system: {}'.format(crs))
    173 
--> 174     if geopolygon and spatial_dims:
    175         raise ValueError('Cannot specify "geopolygon" and one of %s at the same time' % (SPATIAL_KEYS + CRS_KEYS,))
    176 

/g/data/v10/public/modules/agdc-py3-env/20171214/envs/agdc/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
   1119         raise ValueError("The truth value of a {0} is ambiguous. "
   1120                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1121                          .format(self.__class__.__name__))
   1122 
   1123     __bool__ = __nonzero__

ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
```

Code responsible is:

```python
    if geopolygon and spatial_dims:
        raise ValueError('Cannot specify "geopolygon" and one of %s at the same time' % (SPATIAL_KEYS + CRS_KEYS,))
```

Should use `is not None` instead of relying on "to boolean" conversion when checking supplied parameters.
Ambiguous boolean check in `query_geopolygon`
Failure report from NCI install:

```
/g/data/v10/public/modules/agdc-py3/1.5.4/lib/python3.6/site-packages/datacube/api/query.py in query_geopolygon(geopolygon, **kwargs)
    172         raise ValueError('Spatial dimensions must be in the same coordinate reference system: {}'.format(crs))
    173 
--> 174     if geopolygon and spatial_dims:
    175         raise ValueError('Cannot specify "geopolygon" and one of %s at the same time' % (SPATIAL_KEYS + CRS_KEYS,))
    176 

/g/data/v10/public/modules/agdc-py3-env/20171214/envs/agdc/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
   1119         raise ValueError("The truth value of a {0} is ambiguous. "
   1120                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1121                          .format(self.__class__.__name__))
   1122 
   1123     __bool__ = __nonzero__

ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
```

Code responsible is:

```python
    if geopolygon and spatial_dims:
        raise ValueError('Cannot specify "geopolygon" and one of %s at the same time' % (SPATIAL_KEYS + CRS_KEYS,))
```

Should use `is not None` instead of relying on "to boolean" conversion when checking supplied parameters.


Discussion:

Resolving patch:
diff --git a/datacube/api/query.py b/datacube/api/query.py
--- a/datacube/api/query.py
+++ b/datacube/api/query.py
@@ -194,10 +194,13 @@ def query_geopolygon(geopolygon=None, **kwargs):
     elif len(crs) > 1:
         raise ValueError('Spatial dimensions must be in the same coordinate reference system: {}'.format(crs))
 
-    if geopolygon and spatial_dims:
+    if geopolygon is not None and len(spatial_dims) > 0:
         raise ValueError('Cannot specify "geopolygon" and one of %s at the same time' % (SPATIAL_KEYS + CRS_KEYS,))
 
-    return geopolygon or _range_to_geopolygon(**spatial_dims)
+    if geopolygon is None:
+        return _range_to_geopolygon(**spatial_dims)
+
+    return geopolygon
 
 
 def query_group_by(group_by='time', **kwargs):


Test patch: