From 7234c7e1cfaa98ebcf2d7a4878dbd62be1d3529d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 7 Dec 2023 10:01:20 +0100 Subject: [PATCH] Support csv_export2 with dates beyond year 2262 Support is through fmu-ensemble>1.6.5 --- pyproject.toml | 2 +- semeio/workflows/csv_export2/csv_export2.py | 3 -- tests/jobs/csv_export2/test_csvexport2.py | 41 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 716962614..53ceb8f1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies=[ "xlrd", "fmu-steaclient", "pyscal>=0.4.0", - "fmu-ensemble", + "fmu-ensemble>1.6.5", "segyio", "xtgeo>=2.15", ] diff --git a/semeio/workflows/csv_export2/csv_export2.py b/semeio/workflows/csv_export2/csv_export2.py index 8d9a07888..3242bb7bc 100644 --- a/semeio/workflows/csv_export2/csv_export2.py +++ b/semeio/workflows/csv_export2/csv_export2.py @@ -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 = """ diff --git a/tests/jobs/csv_export2/test_csvexport2.py b/tests/jobs/csv_export2/test_csvexport2.py index 252301670..61875c3ad 100644 --- a/tests/jobs/csv_export2/test_csvexport2.py +++ b/tests/jobs/csv_export2/test_csvexport2.py @@ -1,3 +1,4 @@ +import datetime import os import shutil import subprocess @@ -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 @@ -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: