Browse Source

Convert None to NaN before sending data to model #333 (#334)

pull/1/head
Alexandr Velikiy 6 years ago committed by rozetko
parent
commit
1e88ead80a
  1. 1
      analytics/analytics/analytic_unit_manager.py
  2. 10
      analytics/tests/test_dataset.py

1
analytics/analytics/analytic_unit_manager.py

@ -32,6 +32,7 @@ def prepare_data(data: list):
"""
data = pd.DataFrame(data, columns=['timestamp', 'value'])
data['timestamp'] = pd.to_datetime(data['timestamp'], unit='ms')
data.fillna(value = np.nan, inplace = True)
if not np.isnan(data['value'].min()):
data['value'] = data['value'] - min(data['value'])

10
analytics/tests/test_dataset.py

@ -116,6 +116,16 @@ class TestDataset(unittest.TestCase):
except ValueError:
self.fail('Model {} raised unexpectedly'.format(model_name))
def test_prepare_data_output_fon_nan(self):
data_nan = [[1523889000000, np.NaN], [1523889000001, np.NaN], [1523889000002, np.NaN]]
data_none = [[1523889000000, None], [1523889000001, None], [1523889000002, None]]
return_data_nan = prepare_data(data_nan)
return_data_none = prepare_data(data_none)
for item in return_data_nan:
self.assertTrue(np.isnan(item.value))
for item in return_data_none:
self.assertTrue(np.isnan(item.value))
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save