Repository: caglorithm/mopet

Issue:
bool values get transformed to numpy float type
### Description

Problem is that 0 dim arrays get always converted to float without checking the type of the given value. 

### Minimal Example:

```python
import numpy as np
from mopet import mopet

def run(params):
    return {
        "test": True,
        "test2": False
    }

ex = mopet.Exploration(run, {"a": np.arange(0, 1, 0.5)})
ex.run()
ex.load_results()

print(ex.df)
```
Output:
```
     a  test  test2
0    0   1.0    0.0
1  0.5   1.0    0.0
```

Values for test and test2 changed from bool type to numpy float type.



Discussion:

Patch:
diff --git a/mopet/mopet.py b/mopet/mopet.py
index 91b380f..f8abbae 100644
--- a/mopet/mopet.py
+++ b/mopet/mopet.py
@@ -547,11 +547,10 @@ class Exploration:
         for array in group:
             if isinstance(array, tables.array.Array):
                 value = array.read()
-                if not isinstance(value, np.ndarray):
-                    value = np.array(value)
-                # convert 0-dim arrays to floats
-                if value.ndim == 0:
-                    value = np.float(value)
+                # unwrap 0-dim arrays
+                if type(value) is np.ndarray and value.ndim == 0:
+                    value = array.dtype.type(value)
+
                 key = array._v_name
                 return_dict[key] = value
         return return_dict
diff --git a/setup.py b/setup.py
index dc8df4f..4a592e3 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ with open("requirements.txt") as f:
 
 setuptools.setup(
     name="mopet",
-    version="0.1.4",
+    version="0.1.5",
     description="The mildly ominous parameter exploration toolkit",
     long_description=long_description,
     long_description_content_type="text/markdown",


Test patch:
diff --git a/tests/test_exploration.py b/tests/test_exploration.py
index 051cd01..58f91d2 100644
--- a/tests/test_exploration.py
+++ b/tests/test_exploration.py
@@ -63,3 +63,46 @@ class TestExploration(unittest.TestCase):
 
         # Run again, but exploration already exists -> will throw exception.
         self.assertRaises(ExplorationExistsError, ex.run)
+
+    def test_exploration_with_supported_types(self):
+        """
+        Tests if stored result dict containing all supported data types is loaded expected.
+
+        Supported objects are:
+            * NumPy array
+            * Record or scalar
+            * Homogeneous list or tuple
+            * Integer, float, complex or bytes
+
+        This is determined by supported types of array in pytables.
+
+        See here for supported data types in PyTables (https://www.pytables.org/usersguide/datatypes.html).
+
+        """
+        result_dict = {
+            "bool_true": True,
+            "bool_false": False,
+            "bool_array": [True, False],
+            "int": np.int(1),
+            "float": 42.0,
+            "float_array": [1.0, 2.0],
+            "complex": 4 + 3j,
+            "tuple": (1, 2),
+            "bytes": b"\x04",
+        }
+
+        def run(params):
+            return result_dict
+
+        ex = mopet.Exploration(run, {"a": np.arange(0, 1, 0.5)})
+        ex.run()
+        ex.load_results(all=True)
+
+        print(ex.df)
+
+        for key, result in ex.results.items():
+            expected_result = dict(result_dict)
+
+            # tuple is transformed to array by PyTables
+            expected_result["tuple"] = [1, 2]
+            self.assertDictEqual(result, expected_result)