From ca4332e0190b8fab0e74edf0a22ffdaaea5ba37b Mon Sep 17 00:00:00 2001 From: Theodore Chang <tlcfem@gmail.com> Date: Fri, 12 Apr 2024 01:23:08 +0200 Subject: [PATCH] Small fixes --- nomad/app/optimade/filterparser.py | 10 +++++++++- nomad/normalizing/results.py | 6 +++++- .../example.archive.json | 2 +- tests/metainfo/test_metainfo.py | 4 ++-- tests/metainfo/test_quantities.py | 8 +++----- tests/normalizing/test_properties.py | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/nomad/app/optimade/filterparser.py b/nomad/app/optimade/filterparser.py index 9f51b6dc83..ca85b236e5 100644 --- a/nomad/app/optimade/filterparser.py +++ b/nomad/app/optimade/filterparser.py @@ -123,7 +123,15 @@ class ElasticTransformer(OPTElasticTransformer): if quantity.elastic_mapping_type == 'text': query_type = 'match' - elif quantity.elastic_mapping_type in ['keyword', 'integer', 'float', 'bool']: + elif quantity.elastic_mapping_type in [ + 'keyword', + 'short', + 'integer', + 'long', + 'float', + 'double', + 'bool', + ]: query_type = 'term' else: raise NotImplementedError('Quantity has unsupported ES field type') diff --git a/nomad/normalizing/results.py b/nomad/normalizing/results.py index a301e1838e..936e915834 100644 --- a/nomad/normalizing/results.py +++ b/nomad/normalizing/results.py @@ -1059,7 +1059,11 @@ class ResultsNormalizer(Normalizer): msd.diffusion_constant_error_type = ( diffusion_constant.error_type ) - msd.diffusion_constant_errors = diffusion_constant.errors + msd.diffusion_constant_errors = ( + diffusion_constant.errors + if isinstance(diffusion_constant.errors, list) + else [diffusion_constant.errors] + ) md = self.get_md_provenance( msd_workflow.m_parent.m_parent.m_parent diff --git a/tests/data/plugins/perovskite_solar_cell_database/example.archive.json b/tests/data/plugins/perovskite_solar_cell_database/example.archive.json index 59f744665d..39767f81bc 100644 --- a/tests/data/plugins/perovskite_solar_cell_database/example.archive.json +++ b/tests/data/plugins/perovskite_solar_cell_database/example.archive.json @@ -73,7 +73,7 @@ "composition_leadfree": false, "additives_compounds": "Cl", "band_gap": 1.6, - "band_gap_graded": false, + "band_gap_graded": "false", "band_gap_estimation_basis": "Composition", "storage_time_until_next_deposition_step": "Unknown", "storage_atmosphere": "Unknown" diff --git a/tests/metainfo/test_metainfo.py b/tests/metainfo/test_metainfo.py index 4a2d3224f8..565c469441 100644 --- a/tests/metainfo/test_metainfo.py +++ b/tests/metainfo/test_metainfo.py @@ -650,7 +650,7 @@ class TestM1: def test_pd_dataframe_quantity(self): class TestSection(MSection): - test_quantity = Quantity(type=np.dtype('int32')) + test_quantity = Quantity(type=np.dtype('int32'), shape=['*', '*']) test_section = TestSection() test_section.test_quantity = pd.DataFrame([[1, 2]]) @@ -790,7 +790,7 @@ class TestM1: def test_validate_dimension(self): system = System() system.atom_labels = ['H'] - system.atom_positions = [] + system.atom_positions = [[]] assert len(system.m_validate()) > 0 def test_multiple_sub_sections(self): diff --git a/tests/metainfo/test_quantities.py b/tests/metainfo/test_quantities.py index 422a855e42..3e57b2386d 100644 --- a/tests/metainfo/test_quantities.py +++ b/tests/metainfo/test_quantities.py @@ -159,7 +159,7 @@ def test_normalization_string(def_type, orig_value, normalized_value): + [ pytest.param( int, - 'm', + 'inch', [], 100 * units('m'), 100 * units('m'), @@ -299,8 +299,8 @@ def test_complex_number(unit, quantity_type, value, shape): 'im': [[1, 2, 3], [4, 5, 6]], }, # no shape checking anyway np.array([[1, 2, 3], [4, 5, 6]]) + 1j * np.array([[1, 2, 3], [4, 5, 6]]), - ['*'], - id='complex-full', + ['*', '*'], + id='complex-full-2nd', ), ], ) @@ -327,8 +327,6 @@ def test_complex_number_dict(unit, quantity_type, value, result, shape): 'quantity_type,value', [ pytest.param(np.complex128, np.int64(1), id='downcast-from-int-128'), - pytest.param(np.complex64, {'re': 1}, id='downcast-from-int-64'), - pytest.param(np.complex64, {'re': 1.25}, id='downcast-from-float-64'), pytest.param(np.complex128, {'re': [1.25, 1], 'im': 1}, id='mismatch-shape'), pytest.param(np.complex128, {}, id='empty-dict'), ], diff --git a/tests/normalizing/test_properties.py b/tests/normalizing/test_properties.py index 80a3b4a80d..ad82111b39 100644 --- a/tests/normalizing/test_properties.py +++ b/tests/normalizing/test_properties.py @@ -495,7 +495,7 @@ def test_msds(molecular_dynamics): 2.1, ) assert msd.diffusion_constant_error_type == 'Pearson correlation coefficient' - assert np.array_equal(msd.diffusion_constant_errors, 0.98) + assert np.array_equal(msd.diffusion_constant_errors, [0.98]) @pytest.mark.skipif(simulationworkflowschema is None, reason=SCHEMA_IMPORT_ERROR) -- GitLab