Coverage for install/scipp/core/groupby.py: 33%

6 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-04-28 01:28 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Matthew Andrew 

4 

5from typing import Optional, Union 

6 

7from .._scipp import core as _cpp 

8 

9 

10def groupby( 

11 data: Union[_cpp.DataArray, _cpp.Dataset], 

12 /, 

13 group: Union[_cpp.Variable, str], 

14 *, 

15 bins: Optional[_cpp.Variable] = None, 

16) -> Union[_cpp.GroupByDataArray, _cpp.GroupByDataset]: 

17 """Group dataset or data array based on values of specified labels. 

18 

19 Parameters 

20 ---------- 

21 data: 

22 Input data to reduce. 

23 group: 

24 Name of labels to use for grouping or Variable to use for grouping 

25 bins: 

26 Optional bins for grouping label values. 

27 

28 Returns 

29 ------- 

30 : 

31 GroupBy helper object. 

32 """ 

33 if bins is None: 

34 return _cpp.groupby(data, group) 

35 else: 

36 return _cpp.groupby(data, group, bins)