diff --git a/Framework/Kernel/inc/MantidKernel/ContainerDtype.h b/Framework/Kernel/inc/MantidKernel/ContainerDtype.h index 3ecdf326db38168f48a7a14e47a8584a49294ce8..aff76ce18350641e3cdebda00efabd427f45d40d 100644 --- a/Framework/Kernel/inc/MantidKernel/ContainerDtype.h +++ b/Framework/Kernel/inc/MantidKernel/ContainerDtype.h @@ -49,9 +49,9 @@ namespace dtypeHelper { template <template <class> class Container, typename HeldType> std::string dtype(const Container<HeldType>) { if (std::is_same<HeldType, bool>::value) { - return "boolean"; + return "bool_"; } else if (std::is_same<HeldType, short>::value) { - return "short"; + return "int16"; } else if (std::is_same<HeldType, std::int8_t>::value) { return "int8"; } else if (std::is_same<HeldType, std::int16_t>::value) { @@ -61,17 +61,17 @@ std::string dtype(const Container<HeldType>) { } else if (std::is_same<HeldType, std::int64_t>::value) { return "int64"; } else if (std::is_same<HeldType, long>::value) { - return "long"; + return "int_"; } else if (std::is_same<HeldType, long long>::value) { - return "longlong"; + return "int64"; } else if (std::is_same<HeldType, std::float_t>::value) { - return "float"; + return "float32"; } else if (std::is_same<HeldType, std::double_t>::value) { - return "double"; + return "float64"; } else if (std::is_same<HeldType, std::string>::value) { - return "string"; + return "string_"; } else { - return "obj"; + return "object_"; } } diff --git a/Framework/PythonInterface/test/python/mantid/kernel/ArrayPropertyTest.py b/Framework/PythonInterface/test/python/mantid/kernel/ArrayPropertyTest.py index ba08b5b3e974a5cdd3b157d0ee3b5ececf4ab4aa..db5f08d0f2783b2a600c8b6c576f9a78edc110f4 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/ArrayPropertyTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/ArrayPropertyTest.py @@ -150,22 +150,64 @@ class ArrayPropertyTest(unittest.TestCase): int_arr = IntArrayProperty("integers", int_input_values, validator, direc) # Create string array - str_input_values =["a", "b", "c", "d", "e"] + str_input_values = ["a", "b", "c", "d", "e"] str_arr = StringArrayProperty("letters", str_input_values, validator, direc) # Test - self.assertEquals(float_arr.dtype(), "double") - self.assertEquals(str_arr.dtype(), "string") + self.assertEquals(float_arr.dtype(), "float64") + self.assertEquals(str_arr.dtype(), "string_") # Implementation of IntArrayProperty is based on long # (which is itself implementation defined, so a special case is needed here) if sys.platform == 'win32' or sys.platform == 'darwin': - # Windows and macOS should return "long" - self.assertEquals(int_arr.dtype(), "long") + # Windows and macOS should return "int_" + self.assertEquals(int_arr.dtype(), "int_") else: # Linux based systems should return "int64" self.assertEquals(int_arr.dtype(), "int64") + def test_construct_numpy_array_with_given_dtype_float(self): + # Set up + direc = Direction.Output + validator = NullValidator() + + # Create float array + float_input_values = [1.1, 2.5, 5.6, 4.6, 9.0, 6.0] + float_arr = FloatArrayProperty("floats", float_input_values, validator, direc) + + # Use the returned dtype() to check it works with numpy arrays + x = np.arange(1, 10, dtype=float_arr.dtype()) + self.assertIsInstance(x, np.ndarray) + self.assertEquals(x.dtype, float_arr.dtype()) + + def test_construct_numpy_array_with_given_dtype_int(self): + # Set up + direc = Direction.Output + validator = NullValidator() + + # Create int array + int_input_values = [1, 2, 5, 4, 9, 6] + int_arr = IntArrayProperty("integers", int_input_values, validator, direc) + + # Use the returned dtype() to check it works with numpy arrays + x = np.arange(1, 10, dtype=int_arr.dtype()) + self.assertIsInstance(x, np.ndarray) + self.assertEquals(x.dtype, int_arr.dtype()) + + def test_construct_numpy_array_with_given_dtype_string(self): + # Set up + direc = Direction.Output + validator = NullValidator() + + # Create string array + str_input_values = ["hello", "testing", "word", "another word", "word"] + str_arr = StringArrayProperty("letters", str_input_values, validator, direc) + + # Use the returned dtype() to check it works with numpy arrays + x = np.array(str_input_values, dtype=str_arr.dtype()) + self.assertIsInstance(x, np.ndarray) + # Expect longest string to be returned + self.assertEquals(x.dtype, "S12") def test_PythonAlgorithm_setProperty_With_Ranges_String(self): """ diff --git a/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py b/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py index ca07e433b75901e6b11883a7c0c994831a5d90da..d162fc3f5b44c8d0ab9ef1ce8b3fbb03183d38a5 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/TimeSeriesPropertyTest.py @@ -61,7 +61,7 @@ class TimeSeriesPropertyTest(unittest.TestCase): self.assertEquals(log_series.size(), self._ntemp) self.assertAlmostEqual(log_series.nthValue(0), -0.00161) # Check the dtype return value - self.assertEquals(log_series.dtype(), "double") + self.assertEquals(log_series.dtype(), "float64") def test_time_series_int_can_be_extracted(self): log_series = self._test_ws.getRun()["raw_frames"] @@ -77,14 +77,14 @@ class TimeSeriesPropertyTest(unittest.TestCase): self.assertEquals(log_series.size(), 4) self.assertEquals(log_series.nthValue(0).strip(), 'CHANGE_PERIOD 1') # Check the dtype return value - self.assertEquals(log_series.dtype(), "string") + self.assertEquals(log_series.dtype(), "string_") def test_time_series_bool_can_be_extracted(self): log_series = self._test_ws.getRun()["period 1"] self._check_has_time_series_attributes(log_series) self.assertEquals(log_series.size(), 1) # Check the dtype return value - self.assertEquals(log_series.dtype(), "boolean") + self.assertEquals(log_series.dtype(), "bool_") def _check_has_time_series_attributes(self, log, values_type=np.ndarray): self.assertTrue(hasattr(log, "value"))