pymovements.Gaze.drop_nulls#
- Gaze.drop_nulls(subset: list[str] | None = None, how: Literal['all', 'any'] = 'any', events: bool = True) None[source]#
Drop samples and events with null values.
- Parameters:
subset (list[str] | None) – List of column names to check for null values. If None, each frame is checked on its own columns: the samples frame on all sample columns, the events frame on all event columns. If a list is given and events is True, all named columns must exist in both the samples and the events frame. (default: None)
how (Literal['all', 'any']) – If ‘any’, drop rows where any of the specified columns are null. If ‘all’, drop rows where all of the specified columns are null. A nested list column like
pixelorpositioncounts as null if any of its components is null under ‘any’, and only if all of its components are null under ‘all’. (default: ‘any’)events (bool) – If True, also drop events with null values. (default: True)
- Raises:
ValueError – If how is neither ‘any’ nor ‘all’, or if subset contains columns that do not exist in the samples frame, or that do not exist in the events frame while events is True.
Examples
Let’s initialize a Gaze with null pixel components in the samples and an events frame with a null trial value:
>>> import polars >>> import pymovements as pm >>> gaze = pm.Gaze( ... polars.DataFrame({ ... 'time': [0, 1, 2, 3], ... 'x': [0.1, None, None, 0.7], ... 'y': [0.2, 0.4, None, 0.8], ... }), ... pixel_columns=['x', 'y'], ... events=pm.Events( ... polars.DataFrame({ ... 'name': ['fixation', 'fixation', 'fixation'], ... 'onset': [0, 1, 2], ... 'offset': [1, 2, 3], ... 'trial': [1, None, 2], ... }), ... ), ... )
Under
how='all', a sample is only dropped if all of its pixel components are null:>>> gaze.drop_nulls(subset=['pixel'], how='all', events=False) >>> gaze.samples shape: (3, 2) ┌──────┬─────────────┐ │ time ┆ pixel │ │ --- ┆ --- │ │ i64 ┆ list[f64] │ ╞══════╪═════════════╡ │ 0 ┆ [0.1, 0.2] │ │ 1 ┆ [null, 0.4] │ │ 3 ┆ [0.7, 0.8] │ └──────┴─────────────┘
Under the default
how='any', a single null component suffices. The default call also drops events with null values, with each frame checked on its own columns:>>> gaze.drop_nulls() >>> gaze.samples shape: (2, 2) ┌──────┬────────────┐ │ time ┆ pixel │ │ --- ┆ --- │ │ i64 ┆ list[f64] │ ╞══════╪════════════╡ │ 0 ┆ [0.1, 0.2] │ │ 3 ┆ [0.7, 0.8] │ └──────┴────────────┘ >>> gaze.events shape: (2, 5) ┌──────────┬───────┬────────┬───────┬──────────┐ │ name ┆ onset ┆ offset ┆ trial ┆ duration │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ i64 ┆ i64 ┆ i64 ┆ i64 │ ╞══════════╪═══════╪════════╪═══════╪══════════╡ │ fixation ┆ 0 ┆ 1 ┆ 1 ┆ 1 │ │ fixation ┆ 2 ┆ 3 ┆ 2 ┆ 1 │ └──────────┴───────┴────────┴───────┴──────────┘