Skip to content
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

minor refactors in _combine_bounds #545

Merged
merged 1 commit into from
Feb 26, 2019
Merged
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
23 changes: 11 additions & 12 deletions cartoframes/contrib/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,33 +466,32 @@ def dict_all_nones(bbox_dict):
"""Returns True if all dict values are None"""
return all(v is None for v in bbox_dict.values())

# if neither are defined or are all nones, use the world
# if neither are defined, use the world
if not bbox1 and not bbox2:
return WORLD
# if all nones, use the world
if dict_all_nones(bbox1) and dict_all_nones(bbox2):
print([(v, v is None) for v in bbox1.values()])
print([(v, v is None) for v in bbox2.values()])
return WORLD

assert ALL_KEYS == set(bbox1.keys()) and ALL_KEYS == set(bbox2.keys()),\
'Input bounding boxes must have the same dictionary keys'
# create dict with cardinal directions and None-valued keys
outbbox = dict.fromkeys(['west', 'south', 'east', 'north'])

def conv2nan(val):
"""convert Nones to np.nans"""
return np.nan if val is None else val

def maxcoord(coord1, coord2):
"""give the max coordinate"""
return np.nanmax([conv2nan(coord1), conv2nan(coord2)])

def mincoord(coord1, coord2):
return np.nanmin([conv2nan(coord1), conv2nan(coord2)])

# set values and/or defaults
for coord in ('north', 'east'):
outbbox[coord] = maxcoord(bbox1[coord], bbox2[coord])
outbbox[coord] = np.nanmax([
conv2nan(bbox1[coord]),
conv2nan(bbox2[coord])
])
for coord in ('south', 'west'):
outbbox[coord] = mincoord(bbox1[coord], bbox2[coord])
outbbox[coord] = np.nanmin([
conv2nan(bbox1[coord]),
conv2nan(bbox2[coord])
])

return outbbox