Browse Source

ValueError: array must not contain infs or NaNs #563 (#585)

pull/1/head
rozetko 6 years ago committed by GitHub
parent
commit
15ba69dd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      analytics/analytics/utils/common.py
  2. 6
      analytics/tests/test_utils.py

1
analytics/analytics/utils/common.py

@ -309,6 +309,7 @@ def get_correlation(segments: list, av_model: list, data: pd.Series, window_size
return correlation_list return correlation_list
def get_distribution_density(segment: pd.Series) -> float: def get_distribution_density(segment: pd.Series) -> float:
segment.dropna(inplace = True)
if len(segment) < 2 or len(segment.nonzero()[0]) == 0: if len(segment) < 2 or len(segment.nonzero()[0]) == 0:
return (0, 0, 0) return (0, 0, 0)
min_jump = min(segment) min_jump = min(segment)

6
analytics/tests/test_utils.py

@ -195,6 +195,12 @@ class TestUtils(unittest.TestCase):
utils_result_segment = utils.get_distribution_density(segment) utils_result_segment = utils.get_distribution_density(segment)
self.assertEqual(len(utils_result_data), 3) self.assertEqual(len(utils_result_data), 3)
self.assertEqual(utils_result_segment, (0, 0, 0)) self.assertEqual(utils_result_segment, (0, 0, 0))
def test_get_distribution_density_with_nans(self):
segment = [np.NaN, 1, 1, 1, np.NaN, 3, 5, 5, 5, np.NaN]
segment = pd.Series(segment)
result = (3, 5, 1)
self.assertEqual(utils.get_distribution_density(segment), result)
def test_find_pattern_jump_center(self): def test_find_pattern_jump_center(self):
data = [1.0, 1.0, 1.0, 5.0, 5.0, 5.0] data = [1.0, 1.0, 1.0, 5.0, 5.0, 5.0]

Loading…
Cancel
Save