Skip to content

Conversation

@BelhsanHmida
Copy link
Contributor

@BelhsanHmida BelhsanHmida commented Jan 19, 2026

Summary

This PR updates CSV upload handling to allow gaps in the input data, as long as the
gap duration is an integer multiple of the intended base resolution.

Changes

  • Update SensorDataFileSchema.post_load to infer the input event resolution using
    most_common_event_frequency instead of event_frequency.

Rationale

event_frequency is strict and becomes None when data contains gaps, even if the
underlying resolution is still clear. For CSV uploads, we need to infer the intended
base resolution rather than require perfectly regular timestamps.

This change aligns FlexMeasures with the improved frequency handling in timely-beliefs
and allows valid real-world CSV uploads without affecting existing behavior.

How to test:

Automated tests (timely-beliefs)

Run the unit tests that cover regular and gappy data:

pytest timely_beliefs/tests/test_read_csv_frequency.py

These tests verify that:

  • For gappy data where gaps are integer multiples of the base resolution:
    • event_frequency is considered irregular
    • most_common_event_frequency still infers the correct base resolution
  • For regular data:
    • most_common_event_frequency matches event_frequency

Manual testing (CSV upload behavior)

Note:

  • This PR depends on a change in timely-beliefs. To test it locally, you need to
    install timely-beliefs from the PR branch instead of PyPI.
1. CSV with non sensor resolution multiple gaps (should fail):
  • example data:
event_start event_value
2026-01-01T01:00:00.000+01:00 10
2026-01-01T01:15:00.000+01:00 10
2026-01-01T01:30:00.000+01:00 100
2026-01-01T01:45:00.000+01:00 100
2026-01-01T01:48:00.000+01:00 -3.61
2026-01-01T02:00:00.000+01:00 -3.61
  • Expected error:
ValueError: Could not infer a regular time frequency from the uploaded data. Expected step: 0 days 00:15:00. Found 2 irregular intervals. First problematic event_start values: [Timestamp('2026-01-01 01:48:00+0100', tz='Europe/Amsterdam'), Timestamp('2026-01-01 02:00:00+0100', tz='Europe/Amsterdam')]
2. CSV with gaps that are multiples of the resolution (should succeed):
  • example data:
event_start event_value
2026-01-01T01:00:00.000+01:00 10
2026-01-01T01:15:00.000+01:00 10
2026-01-01T01:30:00.000+01:00 100
2026-01-01T01:45:00.000+01:00 100
2026-01-01T02:00:00.000+01:00 -3.61

⚠️ Note: This PR depends on the timely-beliefs PR that introduces

BeliefsDataFrame.most_common_event_frequency. CI will fail until that
PR is merged and released.

Related work

  • Depends on / builds on: timely-beliefs PR #223 (allow gaps in CSV uploads)

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@read-the-docs-community
Copy link

read-the-docs-community bot commented Jan 19, 2026

Documentation build overview

📚 flexmeasures | 🛠️ Build #31086777 | 📁 Comparing 7e1cef3 against latest (64e6040)


🔍 Preview build

Show files changed (2 files in total): 📝 2 modified | ➕ 0 added | ➖ 0 deleted
File Status
changelog.html 📝 modified
api/v3_0.html 📝 modified

Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

I tested this successfully.

Thanks for the detailed PR description. However, the 2nd example (which is supposed to pass) has the same input data as the first (which is failing). Please adjust.

I tested a PT1H sensor with the data below:

datetime, value
2026-01-21T08:00:00, 4
2026-01-21T09:00:00, 5
2026-01-21T10:00:00, 6
2026-01-21T13:00:00, 7
2026-01-21T14:00:00, 8
2026-01-21T15:00:00, 8
2026-01-21T17:00:00, 10
2026-01-21T18:00:00, 11
2026-01-21T20:00:00, 12

And then with this even smaller set (no 3 consecutive measurements):

datetime, value
2026-01-21T09:00:00, 5
2026-01-21T10:00:00, 6
2026-01-21T13:00:00, 7
2026-01-21T14:00:00, 8
2026-01-21T17:00:00, 10
2026-01-21T18:00:00, 11
2026-01-21T20:00:00, 12
Image

@nhoening
Copy link
Contributor

Next to a changelog entry, this PR should also upgrade the TB requirement once that PR is merged and a new version is released.

@BelhsanHmida
Copy link
Contributor Author

BelhsanHmida commented Jan 20, 2026

Next to a changelog entry, this PR should also upgrade the TB requirement once that PR is merged and a new version is released.

I added change-log entry. and yes this pr should wait for the tb pr to be merged and then i will update tb version in requirements.

BelhsanHmida and others added 2 commits January 20, 2026 16:59
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
@nhoening
Copy link
Contributor

nhoening commented Jan 20, 2026

Thanks!

I might still have some changes which could go in this PR, or another one.

  • small fix in drop_unchanged_beliefs() that I encountered
  • improved help text in the upload editor

But we also will fix a UI problem with it, too (toasts are not shown)

@nhoening nhoening changed the title feat: use most_common_event_frequency to get bdf frequency feat: upload allows gaps in data Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants