def test_tz_aggregation(self):
     w = self.widget
     data = Timeseries.from_file('airpassengers')[:20]
     self.send_signal(w.Inputs.time_series, data)
     w.controls.autocommit.click()
     output = self.get_output(w.Outputs.time_series)
     self.assertEqual(output[0][0], "1949-01-01")
예제 #2
0
 def test_time_var_removed(self):
     ts_with_tv = Timeseries.from_file('airpassengers')
     # select columns without time variable
     ts_without_tv = Timeseries.from_data_table(
         ts_with_tv[:, ts_with_tv.domain.class_var])
     self.assertTrue(ts_with_tv.time_variable)
     # make sure the Timeseries without time variable in domain has
     # time_variable set to None
     self.assertIsNone(ts_without_tv.time_variable)
 def test_tz_aggregation(self):
     """ Aggregation should consider timezone """
     w = self.widget
     data = Timeseries.from_file('airpassengers')[:20]
     self.send_signal(w.Inputs.time_series, data)
     # select the first item
     self.select_item(w, 0)
     output = self.get_output(w.Outputs.time_series)
     self.assertEqual(output[0][0], "1949-01-01")
 def test_no_datetime(self):
     """ Raise error if no data with TimeVariable """
     w = self.widget
     time_series = Timeseries.from_file("airpassengers")
     table = Table.from_file('iris')
     self.send_signal(w.Inputs.time_series, time_series)
     self.assertFalse(w.Error.no_time_variable.is_shown())
     self.send_signal(w.Inputs.time_series, table)
     self.assertTrue(w.Error.no_time_variable.is_shown())
     self.send_signal(w.Inputs.time_series, time_series)
     self.assertFalse(w.Error.no_time_variable.is_shown())
 def test_no_time_series(self):
     """
     Clean variables list view when no data.
     GH-46
     """
     w = self.widget
     time_series = Timeseries.from_file("airpassengers")
     self.send_signal(w.Inputs.time_series, time_series)
     self.send_signal(w.Inputs.time_series, None)
     self.send_signal(w.Inputs.forecast, time_series, 1)
     w.configs[0].view.selectAll()
     w.configs[0].selection_changed()
예제 #6
0
    def test_no_instances(self):
        """
        At least two instances are required.
        GH-45
        """
        def assert_error_shown(data, is_shown):
            self.send_signal(self.widget.Inputs.time_series, data)
            self.assertEqual(self.widget.Error.no_instances.is_shown(),
                             is_shown)

        ts = Timeseries.from_file("airpassengers")

        self.assertFalse(self.widget.Error.no_instances.is_shown())
        for data, is_shown in ((ts[:1], True), (ts, False), (ts[:0], True),
                               (None, False)):
            assert_error_shown(data, is_shown)
 def test_new_data(self):
     """
     Widget crashes when it gets new data with different domain.
     GH-50
     """
     w = self.widget
     time_series1 = Timeseries.from_file("airpassengers")
     url = "http://file.biolab.si/datasets/cyber-security-breaches.tab"
     time_series2 = Timeseries.from_url(url)
     self.send_signal(w.Inputs.time_series, time_series1)
     self.select_item(w, 0)
     output1 = self.get_output(w.Outputs.time_series)
     self.send_signal(w.Inputs.time_series, time_series2)
     self.select_item(w, 0)
     output2 = self.get_output(w.Outputs.time_series)
     self.assertNotEqual(output1, output2)
예제 #8
0
 def test_negative_values(self):
     """
     Multiplicative seasonality does not work if there are negative
     values.
     GH-35
     """
     w = self.widget
     table = Timeseries.from_file("iris")
     table.X[1, 1] = -1
     w.decomposition = 1
     w.autocommit = True
     self.assertFalse(w.Error.seasonal_decompose_fail.is_shown())
     self.send_signal(w.Inputs.time_series, table)
     self.widget.view.selectAll()
     self.assertTrue(w.Error.seasonal_decompose_fail.is_shown())
     self.send_signal(w.Inputs.time_series, None)
     self.assertFalse(w.Error.seasonal_decompose_fail.is_shown())
 def setUp(self):
     data = Timeseries.from_file('airpassengers')
     data.Y[:2] = np.nan
     data.Y[10:15] = np.nan
     data.Y[-2:] = np.nan
     self.data = data
예제 #10
0
            times.append(key_time)
            subset = data[list(indices)]

            xs, ys, ms = [], [], []
            for attr, func in self.model:
                values = Table.from_table(
                    Domain([], [], [attr], source=data.domain), subset).metas
                out = (xs if attr in data.domain.attributes else
                       ys if attr in data.domain.class_vars else ms)
                out.append(func(values))

            X.append(xs)
            Y.append(ys)
            M.append(ms)

        ts = Timeseries(Domain([data.time_variable] + attrs, cvars, metas),
                        np.column_stack((times, np.row_stack(X))), np.array(Y),
                        np.array(np.row_stack(M), dtype=object))
        self.Outputs.time_series.send(ts)


if __name__ == "__main__":
    from AnyQt.QtWidgets import QApplication

    a = QApplication([])
    ow = OWAggregate()
    ow.set_data(Timeseries.from_file('airpassengers'))

    ow.show()
    a.exec()
예제 #11
0
    def commit(self):
        self.Outputs.selected_features.send(self.selected_attributes or None)

    def on_select(self):
        selected_rows = self.causality_view.selectionModel().selectedRows()
        row_indices = [i.row() for i in selected_rows]
        row_indices = self.model.mapToSourceRows(row_indices)
        attributes = [
            self.model[i][j]
            for i in row_indices
            for j in [COLUMNS.index("Series 1"), COLUMNS.index("Series 2")]
        ]
        # remove duplicated attributes - I know I could use set for this but
        # I want to keep the order of attributes - keeping first appearance
        # of an attribute and remove the rest
        attributes = list(dict.fromkeys(attributes))
        self.selected_attributes = [self.data.domain[a] for a in attributes]
        self.commit()

    def header_click(self, _):
        # Store the header states
        sort_order = self.model.sortOrder()
        sort_column = self.model.sortColumn()
        self.sorting = (sort_column, sort_order)


if __name__ == "__main__":
    data = Timeseries.from_file("AMZN")
    WidgetPreview(OWGrangerCausality).run(data)
 def setUp(self):
     self.widget: OWGrangerCausality = self.create_widget(OWGrangerCausality)
     dataset_dir = os.path.join(os.path.dirname(__file__), "datasets")
     self.amzn = Timeseries.from_file(os.path.join(dataset_dir, "AMZN.tab"))[:, :-3]
예제 #13
0
 def test_multiple_on_same_dt(self):
     # GH-115
     data = Timeseries.from_file(
         os.path.join(self.dataset_dir, 'multipleonsamedt.csv'))
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #14
0
 def test_numeric_timedelta(self):
     # GH-110
     data = Timeseries.from_file(
         os.path.join(self.dataset_dir, 'numericdt.csv'))
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #15
0
 def setUp(self):
     self.widget = self.create_widget(OWLineChart)  # type: OWLineChart
     self.airpassengers = Timeseries.from_file("airpassengers")
     dataset_dir = os.path.join(os.path.dirname(__file__), "datasets")
     self.amzn = Timeseries.from_file(os.path.join(dataset_dir, "AMZN.tab"))
예제 #16
0
 def setUp(self):
     self.widget = self.create_widget(OWSpiralogram)  # type: OWSpiralogram
     self.passengers = Timeseries.from_file("airpassengers")
     self.philadelphia = Timeseries.from_url(
         'http://datasets.orange.biolab.si/core/philadelphia-crime.csv.xz')
예제 #17
0
 def test_no_timedelta_ts(self):
     # GH-126
     data = Timeseries.from_file(
         os.path.join(self.dataset_dir, 'notddt.csv'))
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #18
0
 def test_unsorted_ts(self):
     data = Timeseries.from_file(
         os.path.join(self.dataset_dir, 'unsortedts.csv'))
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #19
0
 def test_year_timedelta(self):
     data = Timeseries.from_file(
         os.path.join(self.dataset_dir, 'yeardt.csv'))
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #20
0
 def test_month_timedelta(self):
     data = Timeseries.from_file('airpassengers')
     self.widget.set_data(data)
     self.assertTrue(self.widget.Outputs.subset)
예제 #21
0
import unittest
import numpy as np

from orangecontrib.timeseries import Timeseries, periodogram, periodogram_nonequispaced


data = Timeseries.from_file('airpassengers')


class TestPeriodogram(unittest.TestCase):
    def test_periodogram(self):
        periods, pgram = periodogram(data.Y)
        self.assertEqual(max(pgram), 1)
        self.assertEqual(np.round(periods[pgram == 1]), 6)

    def test_periodogram_nonequispaced(self):
        periods, pgram = periodogram_nonequispaced(data.X.ravel(), data.Y, detrend='diff')
        self.assertEqual(max(pgram), 1)
예제 #22
0
 def setUp(self):
     self.widget = self.create_widget(OWAggregate)  # type: OWAggregate
     self.time_series = Timeseries.from_file("airpassengers")