From 33e61b8ccd2556b65d33d25c5a3fb27114f5ff25 Mon Sep 17 00:00:00 2001 From: spaulins-usgs Date: Tue, 25 Jan 2022 14:03:02 -0800 Subject: [PATCH] fix(cellid): Fixes some issues with flopy properly identifying cell ids (#1335) (#1336) --- flopy/mf6/data/mfdatalist.py | 5 ++++- flopy/mf6/data/mfstructure.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/flopy/mf6/data/mfdatalist.py b/flopy/mf6/data/mfdatalist.py index 9ad5ad52a..3c2f45c95 100644 --- a/flopy/mf6/data/mfdatalist.py +++ b/flopy/mf6/data/mfdatalist.py @@ -1423,7 +1423,10 @@ def data_type(self): def dtype(self): data = self.get_data() if len(data) > 0: - return data[0].dtype + if 0 in data: + return data[0].dtype + else: + return next(iter(data.values())).dtype else: return None diff --git a/flopy/mf6/data/mfstructure.py b/flopy/mf6/data/mfstructure.py index ac6f2e976..d96b7e174 100644 --- a/flopy/mf6/data/mfstructure.py +++ b/flopy/mf6/data/mfstructure.py @@ -928,7 +928,11 @@ def set_value(self, line, common): self.name_list.append(self.name) if len(self.name) >= 6 and self.name[0:6] == "cellid": self.is_cellid = True - if self.name and self.name[0:2] == "id": + if ( + self.name + and self.name[0:2] == "id" + and self.type == DatumType.string + ): self.possible_cellid = True self.python_name = self.name.replace("-", "_").lower() # don't allow name to be a python keyword @@ -961,6 +965,12 @@ def set_value(self, line, common): ) self.type_string = type_line[0].lower() self.type = self._str_to_enum_type(type_line[0]) + if ( + self.name + and self.name[0:2] == "id" + and self.type == DatumType.string + ): + self.possible_cellid = True if ( self.type == DatumType.recarray or self.type == DatumType.record @@ -1261,7 +1271,7 @@ def _str_to_enum_type(self, type_string): def get_rec_type(self): item_type = self.type_obj - if item_type == str or self.is_cellid: + if item_type == str or self.is_cellid or self.possible_cellid: return object return item_type