Skip to content

Commit

Permalink
[Python] Make SolutionArray.from_pandas more flexible
Browse files Browse the repository at this point in the history
Add support for data types other than float.
  • Loading branch information
ischoegl committed Jun 22, 2023
1 parent 84ad775 commit f6f7db9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions interfaces/cython/cantera/composite.py
Expand Up @@ -1225,13 +1225,12 @@ def from_pandas(self, df, normalize=True):
The ``normalize`` argument is passed on to `restore_data` to normalize
mole or mass fractions. By default, ``normalize`` is ``True``.
"""

data = df.to_numpy(dtype=float)
labels = list(df.columns)

data_dict = {}
for i, label in enumerate(labels):
data_dict[label] = data[:, i]
for label in list(df.columns):
data_dict[label] = df[label].values
if data_dict[label].dtype.type == np.object_:
# convert object columns to string
data_dict[label] = data_dict[label].astype('U')
self.restore_data(data_dict, normalize)

def save(self, fname, name=None, key=None, description=None,
Expand Down

0 comments on commit f6f7db9

Please sign in to comment.