Skip to content

feat(elt-pipelines): Port electricity_sharepoint pipeline to elt#403

Open
WHTaylor wants to merge 6 commits into
mainfrom
321-port-electricity-sharepoint-pipeline
Open

feat(elt-pipelines): Port electricity_sharepoint pipeline to elt#403
WHTaylor wants to merge 6 commits into
mainfrom
321-port-electricity-sharepoint-pipeline

Conversation

@WHTaylor

Copy link
Copy Markdown
Contributor

ref #321

Ports the electricity_sharepoint pipeline to elt-pipelines.

ELECTRICITY_SHAREPOINT__CLIENT_ID, ELECTRICITY_SHAREPOINT__CLIENT_SECRET, and ELECTRICITY_SHAREPOINT__TENANT_ID need to be set with the sharepoint client details (I've been testing with the ones from vault), and the sharepoint optional-dependencies group needs to be installed.

To backfill, set ELECTRICITY_SHAREPOINT__BACKFILL=True, and optionally set ELECTRICITY_SHAREPOINT__BACKFILL_GLOBS to only pick up specific files.

Most of it is copied directly from the previous pipeline, with these changes:

  • Split the logic for parsing data out of the files into a separate module (it's somewhat complicated, and self-contained)
  • I think fixed a bug in the excel parsing, where the power column wasn't being renamed
    • In the qa db the excel files have read their data into an isis_elec_total_power_mwx column, whereas the csvs read it into isis_elec_total_power_mw. With this version of the pipeline, everything is read into the latter.
  • A few small refactorings, e.g. how the datetime field is extracted from the csvs

I've also combined this pipelines optional dependencies with the ones for the other sharepoint pipeline added in #394, as I figure they'll always be the same (reading from sharepoint, and reading from excel files).


I'm not totally happy with the way watermarking is handled. The watermark is set based on the date_time column from the data, and is used as a threshold for the modified_after time on the files to read, but then because the files are uploaded some time after the last measurement they contain this means we keep rereading the files.

Fixing this will require implementing some way for pipelines to specify how watermarks should be set, rather than always being the max value of a column in the data. Don't think it's high priority, but probably a nice-to-have.

@WHTaylor
WHTaylor requested a review from a team as a code owner July 23, 2026 12:45
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4058fe4d-2f0f-4033-ae5d-43751809b29b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an ETL extractor for electricity exports from SharePoint, supporting configurable backfills, watermark filtering, concurrent downloads, CSV/XLSX parsing, UTC normalisation, combined DataFrame output, and Arrow table emission.

Changes

Electricity SharePoint ingestion

Layer / File(s) Summary
Consumption file parsing and UTC normalisation
elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/parsing.py
Adds Excel parsing and multi-section CSV parsing for automated and manual layouts, normalising timestamps to UTC and mapping power values.
SharePoint extraction and ingestion wiring
elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py, elt-pipelines/pyproject.toml
Adds backfill and watermark configuration, SharePoint file discovery and concurrent reads, combined DataFrame conversion, Arrow output, unsupported-extension handling, and the renamed sharepoint dependency extra.

Possibly related PRs

Suggested reviewers: martyngigg

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: porting the electricity_sharepoint pipeline to elt-pipelines.
Description check ✅ Passed The description is directly related to the changeset and explains the port, backfill behaviour, parsing refactor, and dependency updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py (1)

132-138: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No per-file error isolation in the parsing loop.

If read_as_dataframe raises for any single file (unsupported extension, or an unhandled exception from parsing.py), the whole loop aborts and no data is emitted for the run, including files that parsed fine before the failure. Consider wrapping the per-file call in a try/except that logs and skips the offending file, as a defence-in-depth complement to hardening the individual parsers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py`
around lines 132 - 138, Update the per-file parsing loop around
read_as_dataframe to catch exceptions for individual files, log the
file-specific failure, and continue processing subsequent files. Preserve the
existing df_batch concatenation for successfully parsed DataFrames and return
any accumulated results instead of aborting the entire run.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py`:
- Around line 71-96: Update _extract_electricity_usage after
read_contents_to_dataframe(resolved) to handle a None result before calling
pa.Table.from_pandas. When no files are available or none parse successfully,
yield the pipeline’s appropriate empty PyArrow table; otherwise preserve the
existing DataFrame conversion for valid results.

In `@elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/parsing.py`:
- Around line 116-118: Replace the bare structure assertions in
read_power_consumption_csv with explicit validation that handles malformed
sections locally: verify the CSV has exactly three columns and that the third
column name contains “power”, then skip or return the section using the same
recoverable behavior as the DST branch. Ensure failures do not raise uncaught
AssertionError or terminate read_contents_to_dataframe’s batch loop, and keep
validation active regardless of Python optimization.
- Around line 53-60: Update read_power_consumption_excel to handle pandas DST
ambiguous/nonexistent-time ValueError from _to_utc consistently with
_csv_section_to_df: catch the localization error, log or skip the affected Excel
file using the existing error-handling path, and return the same failure
representation expected by read_contents_to_dataframe so one invalid file does
not abort the batch.

---

Nitpick comments:
In
`@elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py`:
- Around line 132-138: Update the per-file parsing loop around read_as_dataframe
to catch exceptions for individual files, log the file-specific failure, and
continue processing subsequent files. Preserve the existing df_batch
concatenation for successfully parsed DataFrames and return any accumulated
results instead of aborting the entire run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b2d91bdb-9b20-4fb0-aca8-5e526b65de91

📥 Commits

Reviewing files that changed from the base of the PR and between 7acc9eb and b6371cc.

⛔ Files ignored due to path filters (1)
  • elt-pipelines/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/electricity_sharepoint.py
  • elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/parsing.py
  • elt-pipelines/pyproject.toml

Comment thread elt-pipelines/facility_ops/ingest/estates/electricity_sharepoint/parsing.py Outdated
@WHTaylor
WHTaylor requested a review from a team as a code owner July 23, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant