diff --git a/data_tables/logical_types.py b/data_tables/logical_types.py index a76bfdb07..6f381a095 100644 --- a/data_tables/logical_types.py +++ b/data_tables/logical_types.py @@ -121,7 +121,8 @@ def get_logical_types(): def str_to_logical_type(logical_str): - logical_types_dict = get_logical_types() + logical_str = logical_str.lower() + logical_types_dict = {ltype_name.lower(): ltype for ltype_name, ltype in get_logical_types().items()} if logical_str in logical_types_dict: return logical_types_dict[logical_str] diff --git a/data_tables/tests/data_column/test_data_column.py b/data_tables/tests/data_column/test_data_column.py index cc147ea4e..acd1036d8 100644 --- a/data_tables/tests/data_column/test_data_column.py +++ b/data_tables/tests/data_column/test_data_column.py @@ -66,8 +66,9 @@ def test_invalid_logical_type(sample_series): with pytest.raises(TypeError, match=error_message): DataColumn(sample_series, int) - with pytest.raises(TypeError, match=error_message): - DataColumn(sample_series, 'naturallanguage') + error_message = "String naturalllanguage is not a valid logical type" + with pytest.raises(ValueError, match=error_message): + DataColumn(sample_series, 'naturalllanguage') def test_semantic_type_errors(sample_series): diff --git a/data_tables/tests/logical_types/test_logical_types.py b/data_tables/tests/logical_types/test_logical_types.py index b3d65c4e9..f17376fbf 100644 --- a/data_tables/tests/logical_types/test_logical_types.py +++ b/data_tables/tests/logical_types/test_logical_types.py @@ -2,7 +2,8 @@ Boolean, Categorical, LogicalType, - get_logical_types + get_logical_types, + str_to_logical_type ) @@ -28,3 +29,11 @@ def test_get_logical_types(): assert logical_types[logical_type.type_string] == logical_type assert len(logical_types) == 2 * len(all_types) + + +def test_str_to_logical_type(): + all_types = LogicalType.__subclasses__() + + for logical_type in all_types: + assert str_to_logical_type(logical_type.__name__) == logical_type + assert str_to_logical_type(logical_type.type_string) == logical_type