From 5463da78fe6a2dc41267575b12a72aa5a00d232c Mon Sep 17 00:00:00 2001 From: Rob Moss <robm.dev@gmail.com> Date: Wed, 18 Sep 2024 09:37:33 +1000 Subject: [PATCH] Return correct metadata when loading observations --- src/pypfilt/obs.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/pypfilt/obs.py b/src/pypfilt/obs.py index b53eacd..4ad9bb8 100644 --- a/src/pypfilt/obs.py +++ b/src/pypfilt/obs.py @@ -450,16 +450,11 @@ class Univariate(Obs): # Load the data table. fields = [io.time_field(time_col), (value_col, np.float64)] df = io.read_fields(time_scale, filename, fields) - # Rename the columns to 'time' and 'value'. - rename_to = { - time_col: 'time', - value_col: 'value', - } - new_names = tuple( - rename_to.get(name, name) for name in df.dtype.names - ) - df.dtype.names = new_names - return df + # Rename the columns to 'time' and 'value', and ensure that the dtype + # metadata is updated to reflect the renamed columns. + fields_out = [io.time_field('time'), ('value', np.float64)] + dtype_out = io.fields_dtype(time_scale, fields_out) + return df.astype(dtype_out) def row_into_obs(self, row): """ -- GitLab