GAMES-UChile / mogptk

Multi-Output Gaussian Process Toolkit
MIT License
161 stars 42 forks source link

Error with data.remove_range wheen start and end are datetime #74

Closed Clej closed 5 months ago

Clej commented 5 months ago

An ValueError is raised when trying to use 'remove_range'. Reproducing example:

from mogptk.dataset import LoadDataFrame
import pandas as pd

df = pd.DataFrame(
    data={
        'in1': [pd.Timestamp('2019-01-05'), pd.Timestamp('2019-01-15'), pd.Timestamp('2019-01-25')],
        'in2':  [0.0, 1.0, 2.0],
        'out1'    : [1.0, 10.0, 8.0],
        'out2'    : [11.0, 1.0, 9.0]
    }
)
dataset = LoadDataFrame(df, x_col=['in1', 'in2'], y_col=['out1', 'out2'])

for chan in dataset:
    # ret: ValueError "/home/clej/projects/dev_mogptk/mogptk/mogptk/data.py", line 1299, in _normalize_x_val
    # raise ValueError("value must be of type %s" % (self.X_dtypes[i],))
    chan.remove_range(start=pd.Timestamp('2019-01-03'), end=pd.Timestamp('2019-01-17'), dim=0)
    # same for:
    chan.remove_range(start='2019-01-03', end='2019-01-17', dim=0)

returns

Traceback (most recent call last): File "/home/clej/projects/dev_mogptk/mogptk/mogptk/data.py", line 1297, in _normalize_x_val val[i] = np.array(val[i]).astype(self.X_dtypes[i]).astype(np.float64) TypeError: float() argument must be a string or a number, not 'Timestamp'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "volcano/exec/test_mogptk_remove.py", line 17, in chan.remove_range(start=pd.Timestamp('2019-01-03'), end=pd.Timestamp('2019-01-17'), dim=0) File "/home/clej/projects/dev_mogptk/mogptk/mogptk/data.py", line 752, in remove_range start = self._normalize_x_val(start) File "/home/clej/projects/dev_mogptk/mogptk/mogptk/data.py", line 1299, in _normalize_x_val raise ValueError("value must be of type %s" % (self.X_dtypes[i],)) ValueError: value must be of type float64

tdewolff commented 5 months ago

Thank you for the bug report, this should now be fixed in v0.5.2, please let me known if you find any other issues!

Clej commented 5 months ago

Works! thanks 💯