ImperialCollegeLondon / ImperialCollegeLondon/PyProBE

Allow retrieval of preceding row

Open
#374 1 comment 0 reactions 0 assignees Claimed by @tomjholland View on GitHub
Dominant language
Python
Stars
56
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Hi, I've been using a wrapper that includes the row immediately preceding a cycle or step as part of the dataset. It would be great to incorporate this functionality into PyProBE.

The following function can be used with filtering, for example:
- `filter_with_preceding_row(procedure, experiment=experiment_name)`
- `filter_with_preceding_row(experiment, cycle=i)`
- `filter_with_preceding_row(experiment, phase="discharge", step=i)`.

```
import polars as pl

def filter_with_preceding_row(
procedure,
experiment: str | None = None,
cycle: int | None = None,
phase: str | None = None,
step: int | None = None,
):
"""
Obtain the PyProBE result including the preceding row of the data.
"""
data = procedure
if experiment is not None:
data = data.experiment(experiment)
if cycle is not None:
data = data.cycle(cycle)
if phase is not None:
if phase == "discharge":
data = data.discharge()
elif phase == "charge":
data = data.charge()
elif phase == "rest":
data = data.rest()
else:
raise ValueError("Unrecognised phase")
if step is not None:
data = data.step(step)

# Add the preceding row
start_time = data.lf.select("Time [s]").first().collect().item()
preceding_row = procedure.lf.filter(pl.col("Time [s]") < start_time).last()
data.lf = pl.concat((preceding_row, data.lf), how="diagonal_relaxed")

return data
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the proposed filter_with_preceding_row wrapper and the existing experiment, cycle, phase, and step filtering entry points. Compare this request with linked pull request #382; done means filtered results include the immediately preceding row without changing the requested filtering behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.