@@ -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