Skip to content

Commit ed0ccb0

Browse files
committed
doctest fixes
1 parent 618ae45 commit ed0ccb0

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

src/linked_indices/benchmark_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ def benchmark_selection_scaling(
129129
>>> from linked_indices.example_data import create_trial_ndindex_dataset
130130
>>> results = benchmark_selection_scaling(
131131
... create_trial_ndindex_dataset,
132-
... sizes=[(10, 100), (100, 1000)],
133-
... print_results=True,
132+
... sizes=[(10, 100)],
133+
... print_results=False,
134134
... )
135+
>>> len(results)
136+
1
137+
>>> 'index_ms' in results[0] and 'warm_ms' in results[0]
138+
True
135139
"""
136140
results = []
137141

src/linked_indices/nd_index.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ class NDIndex(Index):
110110
>>> from linked_indices.example_data import trial_based_dataset
111111
>>> ds = trial_based_dataset(mode="stacked")
112112
>>> ds_indexed = ds.set_xindex(["abs_time"], NDIndex)
113-
>>> ds_indexed.sel(abs_time=7.5) # Finds trial=1, rel_time=2.5
113+
>>> result = ds_indexed.sel(abs_time=7.5) # Finds trial=1, rel_time=2.5
114+
>>> float(result.abs_time)
115+
7.5
114116
"""
115117

116118
_nd_coords: dict[str, NDCoord]
@@ -622,11 +624,24 @@ def sel_masked(
622624
623625
Examples
624626
--------
625-
>>> # Mask values outside [1.0, 2.0] with NaN
626-
>>> result = index.sel_masked(ds, {'abs_time': slice(1.0, 2.0)}, returns='mask')
627+
>>> from linked_indices import NDIndex
628+
>>> from linked_indices.example_data import trial_based_dataset
629+
>>> ds = trial_based_dataset(n_trials=3, trial_length=5.0, sample_rate=1)
630+
>>> ds = ds.set_xindex(['abs_time'], NDIndex)
631+
>>> index = ds.xindexes['abs_time']
627632
628-
>>> # Add boolean coordinate showing which cells are in range
629-
>>> result = index.sel_masked(ds, {'abs_time': slice(1.0, 2.0)}, returns='metadata')
633+
Mask values outside [1, 8] with NaN:
634+
635+
>>> result = index.sel_masked(ds, {'abs_time': slice(1, 8)}, returns='mask')
636+
>>> import numpy as np
637+
>>> bool(np.any(np.isnan(result['data'].values)))
638+
True
639+
640+
Add boolean coordinate showing which cells are in range:
641+
642+
>>> result = index.sel_masked(ds, {'abs_time': slice(1, 8)}, returns='metadata')
643+
>>> 'in_abs_time_range' in result.coords
644+
True
630645
"""
631646
if returns not in RETURNS_MODES:
632647
raise ValueError(
@@ -784,18 +799,29 @@ def nd_sel(
784799
785800
Examples
786801
--------
787-
>>> from linked_indices import nd_sel
788-
>>> # Standard slice selection (equivalent to ds.sel())
789-
>>> result = nd_sel(ds, abs_time=slice(1.0, 2.0))
802+
>>> from linked_indices import nd_sel, NDIndex
803+
>>> from linked_indices.example_data import trial_based_dataset
804+
>>> ds = trial_based_dataset(n_trials=3, trial_length=5.0, sample_rate=1)
805+
>>> ds = ds.set_xindex(['abs_time'], NDIndex)
806+
807+
Standard slice selection (equivalent to ds.sel()):
808+
809+
>>> result = nd_sel(ds, abs_time=slice(1, 8), returns='slice')
810+
>>> result.sizes['trial']
811+
2
812+
813+
Mask values outside range with NaN:
790814
791-
>>> # Mask values outside range with NaN
792-
>>> result = nd_sel(ds, abs_time=slice(1.0, 2.0), returns='mask')
815+
>>> import numpy as np
816+
>>> result = nd_sel(ds, abs_time=slice(1, 8), returns='mask')
817+
>>> bool(np.any(np.isnan(result['data'].values)))
818+
True
793819
794-
>>> # Add boolean coordinate showing membership
795-
>>> result = nd_sel(ds, abs_time=slice(1.0, 2.0), returns='metadata')
820+
Add boolean coordinate showing membership:
796821
797-
>>> # Combine with method='nearest'
798-
>>> result = nd_sel(ds, abs_time=slice(0.95, 2.1), method='nearest', returns='mask')
822+
>>> result = nd_sel(ds, abs_time=slice(1, 8), returns='metadata')
823+
>>> 'in_abs_time_range' in result.coords
824+
True
799825
"""
800826
# Merge labels dict with kwargs
801827
if labels is None:

0 commit comments

Comments
 (0)