Skip to content

Commit

Permalink
Support csv_export2 with dates beyond year 2262
Browse files Browse the repository at this point in the history
Support is through fmu-ensemble>1.6.5
  • Loading branch information
berland committed Dec 14, 2023
1 parent 370c5f0 commit 243997c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies=[
"xlrd",
"fmu-steaclient",
"pyscal>=0.4.0",
"fmu-ensemble",
"fmu-ensemble>1.6.5",
"segyio",
"xtgeo>=2.15",
]
Expand Down
3 changes: 0 additions & 3 deletions semeio/workflows/csv_export2/csv_export2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
requested in the Eclipse DATA file. A wildcard like ``W*`` can in certain cases
(e.g. Eclipse simulations with 100+ wells) produce thousands of vectors, and can
then be replaced by something more explicit like ``WOPT* WGPT* WWPT*``.
Dates beyond year 2262 are not supported. Use ecl2csv in combination with
merge_csv in such scenarios.
""" # noqa

EXAMPLES = """
Expand Down
41 changes: 41 additions & 0 deletions tests/jobs/csv_export2/test_csvexport2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import os
import shutil
import subprocess
Expand All @@ -6,6 +7,7 @@
import pandas as pd
import pytest
import rstcheck_core.checker
from resdata.summary import Summary

from semeio.workflows.csv_export2 import csv_export2

Expand Down Expand Up @@ -142,6 +144,45 @@ def test_norne_ensemble_noparams():
)


def test_can_export_summary_files_beyond_2262(tmpdir, monkeypatch):
"""Pandas is/has been eager to use datetime64[ns] which overflows in year 2262,
ensure this limitation is sufficiently worked around."""
monkeypatch.chdir(tmpdir)
res_sum = Summary.from_pandas(
"TESTCASE",
pd.DataFrame(
[
{"DATE": datetime.date(2000, 1, 1), "FPR": 200},
{"DATE": datetime.date(2263, 1, 1), "FPR": 1},
]
).set_index("DATE"),
)

Path("realization-0/iter-0").mkdir(parents=True)
os.chdir("realization-0/iter-0")
# fwrite() can only write to cwd
Summary.fwrite(res_sum)
os.chdir("../..")

Path("runpathfile").write_text(
"0 realization-0/iter-0 TESTCASE 0", encoding="utf-8"
)
csv_export2.csv_exporter(
runpathfile="runpathfile",
time_index="yearly",
outputfile="unsmry--yearly.csv",
column_keys=["FPR"],
)
verify_exported_file(
"unsmry--yearly.csv",
["ENSEMBLE", "REAL", "DATE", "FPR"],
{
("iter-0", 0),
},
)
assert "2263-01-01" in Path("unsmry--yearly.csv").read_text(encoding="utf-8")


def verify_exported_file(exported_file_name, result_header, result_iter_rel):
"""Verify an exported CSV file with respect to:
Expand Down

0 comments on commit 243997c

Please sign in to comment.