def test_observation_attributes(self):
     arena = dx.Arena()
     arena.push_model(self.exp)
     titanic = dx.datasets.load_titanic().iloc[1:20]
     arena.push_observations(titanic)  #with m2_price
     arena.push_observations(self.john)  #without m2_price
     attrs = arena.get_params_attributes('observation')
     attrs_name = list(map(lambda x: x.get('name'), attrs))
     self.assertEqual(sorted(attrs_name), sorted(titanic.columns))
     for attr in attrs:
         self.assertTrue(
             all(attr.get('values')[:-1] == titanic[attr.get('name')]))
 def test_server(self):
     arena = dx.Arena()
     arena.push_model(self.exp)
     arena.push_model(self.exp2)
     port = get_free_port()
     try:
         arena.run_server(port=port)
         time.sleep(2)
         self.assertFalse(try_port(port))
         arena.stop_server()
     except AssertionError as e:
         arena.stop_server()
         raise e
 def test_plots(self):
     arena = dx.Arena()
     arena.push_model(self.exp)
     arena.push_observations(self.X.iloc[[1], ])
     arena.fill_cache()
     for p in self.reference_plots:
         ref_counts = list(
             map(lambda param_type: len(arena.list_params(param_type)),
                 p.info.get('requiredParams')))
         count = np.sum([1 for plot in arena.cache if plot.__class__ == p])
         self.assertEqual(np.prod(ref_counts),
                          count,
                          msg="Count of " + str(p))
 def test_variable_attributes(self):
     arena = dx.Arena()
     arena.push_model(self.exp)
     titanic = dx.datasets.load_titanic().iloc[1:20]
     arena.push_observations(titanic)
     attrs = {
         k: arena.get_param_attributes('variable', k)
         for k in self.X.columns
     }
     self.assertEqual(
         attrs, {
             'age': {
                 'type': 'numeric',
                 'min': 0.1666666667,
                 'max': 74.0,
                 'levels': None
             },
             'class': {
                 'type':
                 'categorical',
                 'min':
                 None,
                 'max':
                 None,
                 'levels': [
                     '1st', '2nd', '3rd', 'deck crew', 'engineering crew',
                     'restaurant staff', 'victualling crew'
                 ]
             },
             'embarked': {
                 'type': 'categorical',
                 'min': None,
                 'max': None,
                 'levels':
                 ['Belfast', 'Cherbourg', 'Queenstown', 'Southampton']
             },
             'fare': {
                 'type': 'numeric',
                 'min': 0.0,
                 'max': 512.0607,
                 'levels': None
             },
             'gender': {
                 'type': 'categorical',
                 'min': None,
                 'max': None,
                 'levels': ['female', 'male']
             },
             'parch': {
                 'type': 'numeric',
                 'min': 0,
                 'max': 9,
                 'levels': [0, 1, 2, 3, 4, 5, 6, 9]
             },
             'sibsp': {
                 'type': 'numeric',
                 'min': 0,
                 'max': 8,
                 'levels': [0, 1, 2, 3, 4, 5, 8]
             }
         })