def test_from_group_dataframe(self, index_type):
        """Tests correct extract of TimeSeries groups from a long DataFrame with unsorted (time/integer) index"""
        group = ["a", "a", "a", "b", "b", "b"]
        values = np.arange(len(group))

        if index_type == "int":
            index_expected = pd.RangeIndex(3)
            time = [2, 1, 0, 0, 1, 2]
        else:
            index_expected = pd.date_range("2024-01-01", periods=3)
            time = index_expected[::-1].append(index_expected)
            if index_type == "str":
                time = time.astype(str)

        # create a df with unsorted time
        df = pd.DataFrame({
            "group": group,
            "time": time,
            "x": values,
        })
        ts = TimeSeries.from_group_dataframe(df, group_cols="group", time_col="time")

        # check the time index
        assert ts[0].time_index.equals(index_expected)
        assert ts[1].time_index.equals(index_expected)

        # check the values
        assert (ts[0].values().flatten() == [values[2], values[1], values[0]]).all()
        assert (ts[1].values().flatten() == [values[3], values[4], values[5]]).all()
Tests correct extract of TimeSeries groups from a long DataFrame with unsorted (time/integer) index
darts/tests/test_timeseries_static_covariates.py