Skip to content

Add to_csv/read_csv support for RegularTimeSeries - #115

Merged
ultjeremy merged 10 commits into
HydrologicEngineeringCenter:mainfrom
ultjeremy:dss-to-csv
Jul 10, 2026
Merged

Add to_csv/read_csv support for RegularTimeSeries#115
ultjeremy merged 10 commits into
HydrologicEngineeringCenter:mainfrom
ultjeremy:dss-to-csv

Conversation

@ultjeremy

Copy link
Copy Markdown
Collaborator

regular_timeseries.py:

  • New to_csv() method that exports the RegularTimeSeries data to a .csv file to file_path with the option to include metadata (id, path).
  • New read_csv() static method that reads in a csv at file_path and returns a RegularTimeSeries object.
  • Both new methods support seconds precision.
  • Added extensive tests in test_csv.py.

@ultjeremy
ultjeremy requested review from ktarbet and oskarhurst July 7, 2026 20:52

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

I think we should consider a ISO format for output, and add timezone like the units are handled. But still support reading legacy formats.

Comment thread src/hecdss/regular_timeseries.py Outdated
roll_day = False
# try seconds format first, then minute format
time = None
for fmt in ("%d%b%Y %H%M%S", "%d%b%Y %H%M"):

@ktarbet ktarbet Jul 7, 2026

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.

Consider checking the length of the time string, then you shoud dnot need try/except, and may be better for error control. If we default to ISO we will also need to read that format. perhaps wtih time-zone in each time-stamp.

Comment thread src/hecdss/regular_timeseries.py Outdated
for i in range(len(metadata_rows)):
row = metadata_rows[i]
metadata_value = id_components[i]
if row == 'D': # Skip D by convention

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.

There is a special case where Dpart can be 'ts-pattern' We should keep that one for export, but worth checking if that is also in issue in DSSVue?

Comment thread src/hecdss/regular_timeseries.py Outdated
value = float(val_str) if val_str else 0.0
times.append(time)
values.append(value)
if has_quality and len(row) >= 4:

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.

If you expect quality array, but don't have data, add a zero quality for that row instead of skipping.

@ultjeremy
ultjeremy marked this pull request as draft July 10, 2026 21:36
@ultjeremy
ultjeremy marked this pull request as ready for review July 10, 2026 22:21
@ultjeremy
ultjeremy merged commit 60050c1 into HydrologicEngineeringCenter:main Jul 10, 2026
2 checks passed
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.

2 participants