Skip to content

Commit

Permalink
Only support multiple *_n reductions if they have the same n value
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Feb 27, 2023
1 parent fc833b4 commit b6ed7a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions datashader/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,17 @@ def validate(self, input_dshape):
for v in self.values:
v.validate(input_dshape)

# Check that any included FloatingNReductions have the same n values.
n_values = []
for v in self.values:
if isinstance(v, where):
v = v.selector
if isinstance(v, FloatingNReduction):
n_values.append(v.n)
if len(np.unique(n_values)) > 1:
raise ValueError(
"Using multiple FloatingNReductions with different n values is not supported")

@property
def inputs(self):
return tuple(unique(concat(v.inputs for v in self.values)))
Expand Down
10 changes: 10 additions & 0 deletions datashader/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ def test_summary_where_n(df):
assert_eq_ndarray(agg['max_n'].data, sol_max_n_reverse)


@pytest.mark.parametrize('df', dfs_pd)
def test_summary_different_n(df):
msg = 'Using multiple FloatingNReductions with different n values is not supported'
with pytest.raises(ValueError, match=msg):
c.points(df, 'x', 'y', ds.summary(
min_n=ds.where(ds.min_n('plusminus', 2)),
max_n=ds.where(ds.max_n('plusminus', 3)),
))


@pytest.mark.parametrize('df', dfs)
def test_mean(df):
out = xr.DataArray(values(df.i32).reshape((2, 2, 5)).mean(axis=2, dtype='f8').T,
Expand Down

0 comments on commit b6ed7a5

Please sign in to comment.