Skip to content

Commit

Permalink
Merge pull request scikit-optimize#610 from betatim/categorical-repr
Browse files Browse the repository at this point in the history
[MRG] Fix __repr__ for Categorical dimensions with many options
  • Loading branch information
iaroslav-ai authored Jan 22, 2018
2 parents 7295507 + be7593e commit af08487
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion skopt/space/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def __eq__(self, other):

def __repr__(self):
if len(self.categories) > 7:
cats = self.categories[:3] + [_Ellipsis()] + self.categories[-3:]
cats = self.categories[:3] + (_Ellipsis(), ) + self.categories[-3:]
else:
cats = self.categories

Expand Down
11 changes: 11 additions & 0 deletions skopt/tests/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ def test_categorical_transform_binary():
assert_array_equal(ent_inverse, categories)


@pytest.mark.fast_test
def test_categorical_repr():
small_cat = Categorical([1, 2, 3, 4, 5])
assert (small_cat.__repr__() ==
"Categorical(categories=(1, 2, 3, 4, 5), prior=None)")

big_cat = Categorical([1, 2, 3, 4, 5, 6, 7, 8])
assert (big_cat.__repr__() ==
'Categorical(categories=(1, 2, 3, ..., 6, 7, 8), prior=None)')


@pytest.mark.fast_test
def test_space_consistency():
# Reals (uniform)
Expand Down

0 comments on commit af08487

Please sign in to comment.