From 55a898cd8cfe63a4d3777675a052e98af692383c Mon Sep 17 00:00:00 2001 From: Nils Braun Date: Sun, 17 Nov 2019 16:42:32 +0100 Subject: [PATCH] Make sure there is at least a single column which we can use for data --- tests/units/utilities/test_dataframe_functions.py | 9 +++++++++ tsfresh/utilities/dataframe_functions.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/units/utilities/test_dataframe_functions.py b/tests/units/utilities/test_dataframe_functions.py index f498ee032..8181a976e 100644 --- a/tests/units/utilities/test_dataframe_functions.py +++ b/tests/units/utilities/test_dataframe_functions.py @@ -138,6 +138,15 @@ def test_with_wrong_input(self): self.assertRaises(ValueError, dataframe_functions._normalize_input_to_internal_representation, test_df, None, None, None, "value") + test_df = pd.DataFrame([{"id": 0}]) + self.assertRaises(ValueError, dataframe_functions._normalize_input_to_internal_representation, test_df, + "id", None, None, None) + + test_df = pd.DataFrame([{"id": 0, "sort": 0}]) + self.assertRaises(ValueError, dataframe_functions._normalize_input_to_internal_representation, test_df, + "id", "sort", None, None) + + def test_wide_dataframe_order_preserved_with_sort_column(self): """ verifies that the order of the sort column from a wide time series container is preserved """ diff --git a/tsfresh/utilities/dataframe_functions.py b/tsfresh/utilities/dataframe_functions.py index 381cc7177..8d9a59cbc 100644 --- a/tsfresh/utilities/dataframe_functions.py +++ b/tsfresh/utilities/dataframe_functions.py @@ -321,12 +321,14 @@ def _normalize_input_to_internal_representation(timeseries_container, column_id, column_kind = "_variables" column_value = "_values" + if not set(timeseries_container.columns) - {column_id}: + raise ValueError("There is no column with values in your data!") + timeseries_container.index.name = 'index' timeseries_container = pd.melt(timeseries_container.reset_index(), id_vars=['index', column_id], value_name=column_value, var_name=column_kind) timeseries_container = timeseries_container.set_index('index') - timeseries_container[column_sort] = np.tile(sort, (len(timeseries_container) // len(sort))) # Check kind column