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

Options to binary ops kwargs #1065

Merged
merged 10 commits into from
Nov 12, 2016
18 changes: 10 additions & 8 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,14 +2061,16 @@ def apply_over_both(lhs_data_vars, rhs_data_vars, lhs_vars, rhs_vars):

dest_vars = OrderedDict()

for k in set(lhs_data_vars) & set(rhs_data_vars):
dest_vars[k] = f(lhs_vars[k], rhs_vars[k])
if join in ["outer", "left"]:
for k in set(lhs_data_vars) - set(rhs_data_vars):
dest_vars[k] = lhs_vars[k]
if join in ["outer", "right"]:
for k in set(rhs_data_vars) - set(lhs_data_vars):
dest_vars[k] = rhs_vars[k]
for k in lhs_data_vars:
if k in rhs_data_vars:
dest_vars[k] = f(lhs_vars[k], rhs_vars[k])
elif join in ["left", "outer"]:
dest_vars[k] = lhs_vars[k] if fillna else\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per PEP8, use parenthesis to join across multiple lines instead of \

f(lhs_vars[k], np.nan)
for k in rhs_data_vars:
if k not in dest_vars and join in ["right", "outer"]:
dest_vars[k] = rhs_vars[k] if fillna else\
f(rhs_vars[k], np.nan)
return dest_vars

if utils.is_dict_like(other) and not isinstance(other, Dataset):
Expand Down
4 changes: 0 additions & 4 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def __init__(self, **kwargs):
raise ValueError('argument names %r are not in the set of valid '
'options %r' % (invalid_options, set(OPTIONS)))
self.old = OPTIONS.copy()
for key in kwargs:
if key not in OPTIONS:
raise KeyError("acceptable keys are: {}".\
format(', '.join(OPTIONS.keys())))
OPTIONS.update(kwargs)

def __enter__(self):
Expand Down
8 changes: 4 additions & 4 deletions xarray/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2951,19 +2951,19 @@ def test_binary_op_join_setting(self):
expected = xr.Dataset({'bar': 4}) # default is inner joining
actual = ds1 + ds2
self.assertDatasetEqual(actual, expected)

with xr.set_options(arithmetic_join='outer'):
expected = xr.Dataset({'foo':1, 'bar': 4, 'baz': 3})
expected = xr.Dataset({'foo': np.nan, 'bar': 4, 'baz': np.nan})
actual = ds1 + ds2
self.assertDatasetEqual(actual, expected)

with xr.set_options(arithmetic_join='left'):
expected = xr.Dataset({'foo':1, 'bar': 4})
expected = xr.Dataset({'foo': np.nan, 'bar': 4})
actual = ds1 + ds2
self.assertDatasetEqual(actual, expected)

with xr.set_options(arithmetic_join='right'):
expected = xr.Dataset({'baz':3, 'bar': 4})
expected = xr.Dataset({'bar': 4, 'baz': np.nan})
actual = ds1 + ds2
self.assertDatasetEqual(actual, expected)

Expand Down