diff --git a/ecl2df/parameters.py b/ecl2df/parameters.py index 3db8c7113..b97af9c57 100644 --- a/ecl2df/parameters.py +++ b/ecl2df/parameters.py @@ -3,6 +3,7 @@ import json import logging +import warnings from pathlib import Path from typing import Any, Dict, List, Union @@ -65,9 +66,23 @@ def load_parameterstxt(filename: Union[str, Path]) -> Dict[str, Any]: filename: file containing one key-value pair pr. line, separated by whitespace """ - dframe = pd.read_csv( - filename, comment="#", sep=r"\s", engine="python", names=["KEY", "VALUE"] - ) + with warnings.catch_warnings(record=True): + # From pandas 1.4, too many columns result in a ParserWarning for dropped + # data. This is risky, and therefore catching the warning and raising a + # ParserError instead. + warnings.filterwarnings("error") + try: + dframe = pd.read_csv( + filename, + comment="#", + sep=r"\s", + engine="python", + names=["KEY", "VALUE"], + index_col=False, + ) + except pd.errors.ParserWarning as txt_exc: + raise pd.errors.ParserError(txt_exc) + return dframe.set_index("KEY")["VALUE"].to_dict() diff --git a/setup.py b/setup.py index 7222da8d0..12ce4b765 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ "ecl", "numpy", "opm>=2020.10.2", # NB: Pypi versions. - "pandas<1.4.0", + "pandas", "pyarrow", "pyyaml>=5.1", "treelib",