Skip to content

Commit 2332fe7

Browse files
committed
Add example to doc for _cohorts_to_array
1 parent a97b043 commit 2332fe7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sgkit/cohorts.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,24 @@ def _cohorts_to_array(
3333
Returns
3434
-------
3535
An array of shape ``(len(cohorts), tuple_len)``, where ``tuple_len`` is the length
36-
of the tuples, or 1 if ``cohorts`` is a sequence of values.,
36+
of the tuples, or 1 if ``cohorts`` is a sequence of values.
3737
3838
Raises
3939
------
4040
ValueError
4141
If the cohort tuples are not all the same length.
42+
43+
Examples
44+
--------
45+
46+
>>> import pandas as pd
47+
>>> from sgkit.cohorts import _cohorts_to_array
48+
>>> _cohorts_to_array([(0, 1), (2, 1)]) # doctest: +SKIP
49+
array([[0, 1],
50+
[2, 1]], dtype=int32)
51+
>>> _cohorts_to_array([("c0", "c1"), ("c2", "c1")], pd.Index(["c0", "c1", "c2"])) # doctest: +SKIP
52+
array([[0, 1],
53+
[2, 1]], dtype=int32)
4254
"""
4355
if len(cohorts) == 0:
4456
return np.array([], np.int32)

0 commit comments

Comments
 (0)