Skip to content

Commit

Permalink
Make case agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamar Grey committed Sep 14, 2020
1 parent 5e5afda commit 90750f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion data_tables/logical_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions data_tables/tests/data_column/test_data_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion data_tables/tests/logical_types/test_logical_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Boolean,
Categorical,
LogicalType,
get_logical_types
get_logical_types,
str_to_logical_type
)


Expand All @@ -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

0 comments on commit 90750f8

Please sign in to comment.