Skip to content

Commit

Permalink
Add ColumnSchema repr (#817)
Browse files Browse the repository at this point in the history
* Add ColumnSchema repr

* Add release note

* remove name from docstring
  • Loading branch information
tamargrey committed Apr 15, 2021
1 parent c88e129 commit 8359fb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Expand Up @@ -13,6 +13,7 @@ Release Notes
* Add validation control to ``deserialize.read_woodwork_table`` and ``ww.read_csv`` (:pr:`788`)
* Add ``WoodworkColumnAccessor.schema`` and handle copying column schema (:pr:`799`)
* Allow initializing a ``WoodworkColumnAccessor`` with a ``ColumnSchema`` (:pr:`814`)
* Add ``__repr__`` to ``ColumnSchema`` (:pr:`817`)
* Fixes
* Changes
* Rename ``FullName`` logical type to ``PersonFullName`` (:pr:`740`)
Expand Down
10 changes: 9 additions & 1 deletion woodwork/column_schema.py
Expand Up @@ -21,7 +21,6 @@ def __init__(self,
"""Create ColumnSchema
Args:
name (str, optional): The name of the column.
logical_type (str, LogicalType, optional): The column's LogicalType.
semantic_tags (str, list, set, optional): The semantic tag(s) specified for the column.
use_standard_tags (boolean, optional): If True, will add standard semantic tags to the column based
Expand Down Expand Up @@ -61,6 +60,15 @@ def __eq__(self, other):

return True

def __repr__(self):
msg = "<ColumnSchema"
if self.logical_type is not None:
msg += u" (Logical Type = {})".format(self.logical_type)
if self.semantic_tags:
msg += u" (Semantic Tags = {})".format(sorted(list(self.semantic_tags)))
msg += ">"
return msg


def _validate_logical_type(logical_type):
ltype_class = _get_ltype_class(logical_type)
Expand Down
11 changes: 11 additions & 0 deletions woodwork/tests/schema/test_column_schema.py
Expand Up @@ -234,3 +234,14 @@ def test_schema_equality():
assert datetime_col != datetime_col_instantiated
assert datetime_col_instantiated != datetime_col_format
assert datetime_col_instantiated == datetime_col_param


def test_schema_repr():
assert (repr(ColumnSchema(logical_type=Datetime, semantic_tags='time_index')) ==
"<ColumnSchema (Logical Type = Datetime) (Semantic Tags = ['time_index'])>")
assert (repr(ColumnSchema(logical_type=Integer)) ==
"<ColumnSchema (Logical Type = Integer)>")
assert (repr(ColumnSchema(semantic_tags={'category', 'foreign_key'})) ==
"<ColumnSchema (Semantic Tags = ['category', 'foreign_key'])>")
assert (repr(ColumnSchema()) ==
"<ColumnSchema>")

0 comments on commit 8359fb1

Please sign in to comment.