diff --git a/tests/feature_extraction/test_feature_calculations.py b/tests/feature_extraction/test_feature_calculations.py index 484083928..3bc13d444 100644 --- a/tests/feature_extraction/test_feature_calculations.py +++ b/tests/feature_extraction/test_feature_calculations.py @@ -9,6 +9,7 @@ from unittest import TestCase from tsfresh.feature_extraction.feature_calculators import * from tsfresh.feature_extraction.feature_calculators import _get_length_sequences_where +from sys import version_info class FeatureCalculationTestCase(TestCase): @@ -279,7 +280,10 @@ def test_mass_quantile(self): expected_index = ["TEST__index_mass_quantile__q_0.5"] res = index_mass_quantile(x, c, param) self.assertIsInstance(res, pd.Series) - self.assertItemsEqual(list(res.index), expected_index) + if int(version_info[0]) == 2: + self.assertItemsEqual(list(res.index), expected_index) + else: + self.assertCountEqual(list(res.index), expected_index) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.5"], 0.5, places=1) x = [0] * 1000 + [1] @@ -288,7 +292,10 @@ def test_mass_quantile(self): expected_index = ["TEST__index_mass_quantile__q_0.5", "TEST__index_mass_quantile__q_0.99"] res = index_mass_quantile(x, c, param) self.assertIsInstance(res, pd.Series) - self.assertItemsEqual(list(res.index), expected_index) + if int(version_info[0]) == 2: + self.assertItemsEqual(list(res.index), expected_index) + else: + self.assertCountEqual(list(res.index), expected_index) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.5"], 1, places=1) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.99"], 1, places=1) @@ -299,7 +306,11 @@ def test_mass_quantile(self): "TEST__index_mass_quantile__q_0.9"] res = index_mass_quantile(x, c, param) self.assertIsInstance(res, pd.Series) - self.assertItemsEqual(list(res.index), expected_index) + + if int(version_info[0]) == 2: + self.assertItemsEqual(list(res.index), expected_index) + else: + self.assertCountEqual(list(res.index), expected_index) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.3"], 0.25, places=1) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.6"], 0.375, places=1) self.assertAlmostEqual(res["TEST__index_mass_quantile__q_0.9"], 0.75, places=1) @@ -331,7 +342,10 @@ def test_ar_coefficient(self): expected_index = ["TEST__ar_coefficient__k_1__coeff_0", "TEST__ar_coefficient__k_1__coeff_1"] self.assertIsInstance(res, pd.Series) - self.assertItemsEqual(list(res.index), expected_index) + if int(version_info[0]) == 2: + self.assertItemsEqual(list(res.index), expected_index) + else: + self.assertCountEqual(list(res.index), expected_index) self.assertAlmostEqual(res["TEST__ar_coefficient__k_1__coeff_0"], 1, places=2) self.assertAlmostEqual(res["TEST__ar_coefficient__k_1__coeff_1"], 2.5, places=2) @@ -350,10 +364,12 @@ def test_ar_coefficient(self): "TEST__ar_coefficient__k_2__coeff_0", "TEST__ar_coefficient__k_2__coeff_1", "TEST__ar_coefficient__k_2__coeff_2", "TEST__ar_coefficient__k_2__coeff_3"] - print(res.sort_index()) self.assertIsInstance(res, pd.Series) - self.assertItemsEqual(list(res.index), expected_index) + if int(version_info[0]) == 2: + self.assertItemsEqual(list(res.index), expected_index) + else: + self.assertCountEqual(list(res.index), expected_index) self.assertAlmostEqual(res["TEST__ar_coefficient__k_2__coeff_0"], 1, places=2) self.assertAlmostEqual(res["TEST__ar_coefficient__k_2__coeff_1"], 3.5, places=2) self.assertAlmostEqual(res["TEST__ar_coefficient__k_2__coeff_2"], -2, places=2) @@ -428,4 +444,4 @@ def test_range_count(self): self.assertEqualPandasSeriesWrapper(range_count, list(range(10)), 9, min=0, max=9) self.assertEqualPandasSeriesWrapper(range_count, list(range(10)), 10, min=0, max=10) self.assertEqualPandasSeriesWrapper(range_count, list(range(0, -10, -1)), 9, min=-10, max=0) - self.assertEqualPandasSeriesWrapper(range_count, [np.NaN, np.PINF, np.NINF] + list(range(10)), 10, min=0, max=10) \ No newline at end of file + self.assertEqualPandasSeriesWrapper(range_count, [np.NaN, np.PINF, np.NINF] + list(range(10)), 10, min=0, max=10) diff --git a/tests/feature_extraction/test_settings.py b/tests/feature_extraction/test_settings.py index 34d3f163f..e61db1112 100644 --- a/tests/feature_extraction/test_settings.py +++ b/tests/feature_extraction/test_settings.py @@ -9,6 +9,8 @@ import numpy as np from tsfresh.feature_extraction.settings import FeatureExtractionSettings +from sys import version_info + class TestSettingsObject(TestCase): @@ -36,13 +38,18 @@ def test_from_columns(self): cset = fset.from_columns(feature_names) - self.assertItemsEqual(list(cset.kind_to_calculation_settings_mapping[tsn].keys()), - ["sum_values", "median", "length", "quantile", "number_peaks", "ar_coefficient", - "value_count"]) + if int(version_info[0]) == 2: + self.assertItemsEqual(list(cset.kind_to_calculation_settings_mapping[tsn].keys()), + ["sum_values", "median", "length", "quantile", "number_peaks", "ar_coefficient", + "value_count"]) + else: + self.assertCountEqual(list(cset.kind_to_calculation_settings_mapping[tsn].keys()), + ["sum_values", "median", "length", "quantile", "number_peaks", "ar_coefficient", + "value_count"]) self.assertEqual(cset.kind_to_calculation_settings_mapping[tsn]["sum_values"], None) self.assertEqual(cset.kind_to_calculation_settings_mapping[tsn]["ar_coefficient"], [{"k": 20, "coeff": 4}, {"k": -1, "coeff": 10}]) self.assertEqual(cset.kind_to_calculation_settings_mapping[tsn]["value_count"], - [{"value": np.PINF}, {"value": np.NINF}, {"value": np.NaN}]) \ No newline at end of file + [{"value": np.PINF}, {"value": np.NINF}, {"value": np.NaN}]) diff --git a/tests/feature_extraction/test_ts_features.py b/tests/feature_extraction/test_ts_features.py index ebc2eefc2..20081b313 100644 --- a/tests/feature_extraction/test_ts_features.py +++ b/tests/feature_extraction/test_ts_features.py @@ -8,6 +8,7 @@ from tests.fixtures import DataTestCase from tsfresh.feature_extraction.extraction import extract_features from tsfresh.feature_extraction.settings import FeatureExtractionSettings +from sys import version_info class FeatureExtractorTestCase(DataTestCase): @@ -48,7 +49,10 @@ def test_calculate_ts_features_after_randomisation(self): extracted_features_from_random = extract_features(df_random, self.settings, "id", "sort", "kind", "val").sort_index() - self.assertItemsEqual(extracted_features.columns, extracted_features_from_random.columns) + if int(version_info[0]) == 2: + self.assertItemsEqual(extracted_features.columns, extracted_features_from_random.columns) + else: + self.assertCountEqual(extracted_features.columns, extracted_features_from_random.columns) for col in extracted_features: self.assertIsNone(np.testing.assert_array_almost_equal(extracted_features[col], diff --git a/tests/fixtures.py b/tests/fixtures.py index f50a2218e..d308f30ee 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -41,7 +41,11 @@ def create_test_data_sample_with_target(self): :return: target y which is the mean of each sample's timeseries """ cid = np.repeat(range(50), 3) - csort = range(3) * 50 + # The csort was changed for Python 3 support + # https://github.com/blue-yonder/tsfresh/issues/8 + # range has changed type in py3 from list to class + # csort = range(3) * 50 + csort = list(range(3)) * 50 cval = [1, 2, 3] * 30 + [4, 5, 6] * 20 df = pd.DataFrame({'id': cid, 'kind': 'a', 'sort': csort, 'val': cval}) y = pd.Series([2] * 30 + [5] * 20) diff --git a/tests/transformers/test_feature_augmenter.py b/tests/transformers/test_feature_augmenter.py index cfaa21403..ec29bf7cf 100644 --- a/tests/transformers/test_feature_augmenter.py +++ b/tests/transformers/test_feature_augmenter.py @@ -25,6 +25,29 @@ def test_fit_and_transform(self): # Fit should do nothing returned_df = augmenter.fit() + # Changed for py3 as unittest.assertEqual has changed a little + # TODO in progress + # Tried patterns, back at the original for now so can commit the + # assertItemsEqual assertCountEqual fix + # self.assertEqual(returned_df, augmenter) +#> self.assertEqual(list(X_transformed.columns), ["feature_1", "a__length", "b__length"]) +#E AssertionError: Lists differ: ['feature_1', 'b__length', 'a__length'] != ['feature_1', 'a__length', 'b__length'] +#E +#E First differing element 1: +#E 'b__length' +#E 'a__length' +#E +#E - ['feature_1', 'b__length', 'a__length'] +#E + ['feature_1', 'a__length', 'b__length'] + +# self.assertEqual(sorted(returned_df), sorted((augmenter)) +#> self.assertEqual(sorted(returned_df), sorted(augmenter)) +#E TypeError: 'FeatureAugmenter' object is not iterable + +# self.assertEqual(sorted(returned_df), sorted(list(augmenter))) +#> self.assertEqual(sorted(returned_df), sorted(list(augmenter))) +#E TypeError: 'FeatureAugmenter' object is not iterable + self.assertEqual(returned_df, augmenter) self.assertRaises(RuntimeError, augmenter.transform, None) @@ -75,4 +98,4 @@ def test_add_features_to_only_a_part(self): for index, row in X_transformed.iterrows(): print((index, row)) self.assertFalse(np.isnan(row["a__length"])) - self.assertFalse(np.isnan(row["b__length"])) \ No newline at end of file + self.assertFalse(np.isnan(row["b__length"]))