From 5e9fbf1cb1ae12b6f6bbbaba3e7bc13f5a20adb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Mon, 16 May 2022 11:39:14 +0200 Subject: [PATCH 1/5] MSH: use engine='python' as fallback in pandas to read ogs mesh --- ogs5py/fileclasses/msh/msh_io.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ogs5py/fileclasses/msh/msh_io.py b/ogs5py/fileclasses/msh/msh_io.py index 3f9a143..d15a146 100755 --- a/ogs5py/fileclasses/msh/msh_io.py +++ b/ogs5py/fileclasses/msh/msh_io.py @@ -186,13 +186,16 @@ def load_ogs5msh( filepos = msh.tell() # read the elements with pandas # names=range(max_node_no) to assure rectangular shape by cols - tmp = pd.read_csv( - msh, - engine="c", + pd_kwargs = dict( delim_whitespace=True, nrows=no_elements, names=range(max_node_no + 4), # +4 for the "-1" entry - ).values + ) + try: + tmp = pd.read_csv(msh, engine="c", **pd_kwargs).values + except pd.errors.ParserError: + msh.seek(filepos) + tmp = pd.read_csv(msh, engine="python", **pd_kwargs).values # check if all given element-typs are OGS known pos_ele = 2 # can be shift to right, if "-1" occures check_elem = np.in1d(tmp[:, pos_ele], ELEM_NAMES) From 03319840142e3dc199016958806f73adfb2cb0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Mon, 16 May 2022 12:57:47 +0200 Subject: [PATCH 2/5] py3: remove io.open imports --- ogs5py/fileclasses/base.py | 6 ------ ogs5py/fileclasses/gem/core.py | 3 --- ogs5py/fileclasses/gli/tools.py | 2 -- ogs5py/fileclasses/ic/core.py | 2 -- ogs5py/fileclasses/msh/msh_io.py | 4 ---- 5 files changed, 17 deletions(-) diff --git a/ogs5py/fileclasses/base.py b/ogs5py/fileclasses/base.py index f9d6a84..7182d43 100644 --- a/ogs5py/fileclasses/base.py +++ b/ogs5py/fileclasses/base.py @@ -343,9 +343,6 @@ def read_file(self, path, encoding=None, verbose=False): verbose : bool, optional Print information of the reading process. Default: False """ - # in python3 open was replaced with io.open - # so we can use encoding keyword in python2 - from io import open self.reset() try: @@ -941,9 +938,6 @@ def read_file(self, path, encoding=None, verbose=False): verbose : bool, optional Print information of the reading process. Default: False """ - # in python3 open was replaced with io.open - # so we can use encoding key word in python2 - from io import open self.reset() diff --git a/ogs5py/fileclasses/gem/core.py b/ogs5py/fileclasses/gem/core.py index 7d8b772..81a99b6 100644 --- a/ogs5py/fileclasses/gem/core.py +++ b/ogs5py/fileclasses/gem/core.py @@ -303,9 +303,6 @@ def read_file(self, path, encoding=None, verbose=False): ----- This also reads the given files in the lst-file. (dch, ipm, dbr) """ - # in python3 open was replaced with io.open - # so we can use encoding key word in python2 - from io import open root = os.path.dirname(path) diff --git a/ogs5py/fileclasses/gli/tools.py b/ogs5py/fileclasses/gli/tools.py index 2569c16..e00cc75 100644 --- a/ogs5py/fileclasses/gli/tools.py +++ b/ogs5py/fileclasses/gli/tools.py @@ -70,8 +70,6 @@ def load_ogs5gli(filepath, verbose=True, encoding=None): - ``LAYER`` (int or None) """ - # in python3 open was replaced with io.open - from io import open out = dcp(EMPTY_GLI) diff --git a/ogs5py/fileclasses/ic/core.py b/ogs5py/fileclasses/ic/core.py index 1655d81..3f6e040 100644 --- a/ogs5py/fileclasses/ic/core.py +++ b/ogs5py/fileclasses/ic/core.py @@ -309,8 +309,6 @@ def save(self, path, **kwargs): def read_file(self, path, encoding=None, verbose=False): """Write the actual RFR input file to the given folder.""" - # in python3 open was replaced with io.open - from io import open headers = [] variables = [] diff --git a/ogs5py/fileclasses/msh/msh_io.py b/ogs5py/fileclasses/msh/msh_io.py index d15a146..a3cc79e 100755 --- a/ogs5py/fileclasses/msh/msh_io.py +++ b/ogs5py/fileclasses/msh/msh_io.py @@ -74,8 +74,6 @@ def load_ogs5msh( The $AREA keyword within the Nodes definition is NOT supported and will violate the read data if present. """ - # in python3 open was replaced with io.open - from io import open import pandas as pd @@ -304,8 +302,6 @@ def load_ogs5msh_old(filepath, verbose=True, max_node_no=8, encoding=None): element_id : dict contains element ids for each element sorted by element types """ - # in python3 open was replaced with io.open - from io import open import pandas as pd From f640e714a8c68b186da94b4dc4c8ff35163cf07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Mon, 23 May 2022 14:44:36 +0200 Subject: [PATCH 3/5] msh_io: add pandas python engine fallback to 'load_ogs5msh_old' --- ogs5py/fileclasses/msh/msh_io.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ogs5py/fileclasses/msh/msh_io.py b/ogs5py/fileclasses/msh/msh_io.py index a3cc79e..617faac 100755 --- a/ogs5py/fileclasses/msh/msh_io.py +++ b/ogs5py/fileclasses/msh/msh_io.py @@ -335,13 +335,17 @@ def load_ogs5msh_old(filepath, verbose=True, max_node_no=8, encoding=None): print(no_elements) # read the elements with pandas # names=range(max_node_no) to assure rectangular shape by cols - tmp = pd.read_csv( - msh, - engine="c", + filepos = msh.tell() + pd_kwargs = dict( delim_whitespace=True, nrows=no_elements, names=range(max_node_no + 4), # +4 for the "-1" entry - ).values + ) + try: + tmp = pd.read_csv(msh, engine="c", **pd_kwargs).values + except pd.errors.ParserError: + msh.seek(filepos) + tmp = pd.read_csv(msh, engine="python", **pd_kwargs).values # check if all given element-typs are OGS known pos_ele = 2 # can be shift to right, if "-1" occures check_elem = np.in1d(tmp[:, pos_ele], ELEM_NAMES) From e9df6477f07cca5fb17c703eb91b4926f035de06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 25 May 2022 20:46:23 +0200 Subject: [PATCH 4/5] update changelog for v1.2.2 --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd17051..79219e5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to **ogs5py** will be documented in this file. +## [1.2.2] - 2022-05-25 + +### Bugfixes +* `MSH.load`: use `engine='python'` as fallback in pandas to read ogs mesh [#16](https://github.com/GeoStat-Framework/ogs5py/pull/16) +* removed redundant `from io import open` which were there for py2 compatibility [#16](https://github.com/GeoStat-Framework/ogs5py/pull/16) + + ## [1.2.1] - 2022-05-15 ### Enhancements @@ -178,7 +185,8 @@ All notable changes to **ogs5py** will be documented in this file. First release of ogs5py. -[Unreleased]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.1...HEAD +[Unreleased]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.2...HEAD +[1.2.2]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.1.1...v1.2.0 [1.1.1]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.1.0...v1.1.1 From a6107fb852af2408edd588b9da30891ff1efd038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 25 May 2022 21:33:05 +0200 Subject: [PATCH 5/5] update changelog (m2r2 fix) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79219e5..53d8b51 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to **ogs5py** will be documented in this file. ## [1.2.2] - 2022-05-25 ### Bugfixes -* `MSH.load`: use `engine='python'` as fallback in pandas to read ogs mesh [#16](https://github.com/GeoStat-Framework/ogs5py/pull/16) +* `MSH.load` now uses `engine="python"` as fallback in pandas to successfully read ogs meshes in some corner cases [#16](https://github.com/GeoStat-Framework/ogs5py/pull/16) * removed redundant `from io import open` which were there for py2 compatibility [#16](https://github.com/GeoStat-Framework/ogs5py/pull/16)