Skip to content

Commit

Permalink
rollbach on str type
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-vignal committed Oct 10, 2024
1 parent 101164c commit 93b1fcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions shapash/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def is_nested_list(object_param):
return any(isinstance(elem, list) for elem in object_param)


def add_line_break(text, nbchar, maxlen=150):
def add_line_break(value, nbchar, maxlen=150):
"""
adding line break in string if necessary
Parameters
----------
text : string
string to check in order to add line break
value : string or oither type
if string to check in order to add line break
nbchar : int
number of characters before line break
maxlen : int
Expand All @@ -91,10 +91,10 @@ def add_line_break(text, nbchar, maxlen=150):
string
original text + line break
"""
if isinstance(text, str):
if isinstance(value, str):
length = 0
tot_length = 0
input_word = text.split()
input_word = value.split()
final_sep = []
for w in input_word[:-1]:
length = length + len(w)
Expand All @@ -113,7 +113,7 @@ def add_line_break(text, nbchar, maxlen=150):
new_string = "".join(sum(zip(input_word, final_sep + [""]), ())[:-1]) + last_char
return new_string
else:
return str(text)
return value


def truncate_str(text, maxlen=40):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/explainer/test_smart_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,11 +1860,11 @@ def test_interactions_plot_3(self):

output = smart_explainer.plot.interactions_plot(col2, col1, violin_maxf=0)

assert np.array_equal(output.data[0].x, ["34.0"])
assert np.array_equal(output.data[0].x, [34.0])
assert np.array_equal(output.data[0].y, [-1.4])
assert output.data[0].name == "PhD"

assert np.array_equal(output.data[1].x, ["27.0"])
assert np.array_equal(output.data[1].x, [27.0])
assert np.array_equal(output.data[1].y, [-0.2])
assert output.data[1].name == "Master"

Expand Down Expand Up @@ -1893,7 +1893,7 @@ def test_interactions_plot_4(self):

output = smart_explainer.plot.interactions_plot(col1, col2, violin_maxf=0)

assert np.array_equal(output.data[0].x, ["520.0", "12800.0"])
assert np.array_equal(output.data[0].x, [520, 12800])
assert np.array_equal(output.data[0].y, [-1.4, -0.2])
assert np.array_equal(output.data[0].marker.color, [34.0, 27.0])

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_truncate_str_3(self):

def test_add_line_break_1(self):
t = add_line_break(3453, 10)
assert t == "3453"
assert t == 3453

def test_add_line_break_2(self):
t = add_line_break("this is a very long sentence in order to make a very great test", 10)
Expand Down

0 comments on commit 93b1fcd

Please sign in to comment.