Skip to content

Commit

Permalink
The xlsx parser no longer assume column 0 as the index column. It all…
Browse files Browse the repository at this point in the history
…ows sheets without `uid` to be parsed correctly.
  • Loading branch information
cuihantao committed Aug 10, 2023
1 parent af9e4e6 commit 0289e00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions andes/core/model/modeldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def as_dict(self, vin=False):
An additional `uid` key is added with the value default to range(n).
"""
out = dict()

# append 0-indexed `uid`
out['uid'] = np.arange(self.n)

for name, instance in self.params.items():
Expand Down
2 changes: 1 addition & 1 deletion andes/io/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def read(system, infile):
"""
df_models = pd.read_excel(infile,
sheet_name=None,
index_col=0,
index_col=None,
engine='openpyxl',
)

Expand Down
3 changes: 3 additions & 0 deletions andes/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ def add(self, model, param_dict=None, **kwargs):
if kwargs is not None:
param_dict.update(kwargs)

# remove `uid` field
param_dict.pop('uid', None)

idx = param_dict.pop('idx', None)
if idx is not None and (not isinstance(idx, str) and np.isnan(idx)):
idx = None
Expand Down

0 comments on commit 0289e00

Please sign in to comment.