Skip to content

Commit 2155380

Browse files
committed
mitosheet: fix bug with conditional format string conditions
1 parent 37d9f38 commit 2155380

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

mitosheet/mitosheet/pro/conditional_formatting_utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ def get_conditonal_formatting_result(
4949

5050
for index in applied_indexes:
5151
# We need to make this index valid json, and do so in a way that is consistent with how indexes
52-
# are sent to the frontend
53-
json_index = json.dumps(index, cls=NpEncoder)
52+
# are sent to the frontend. However, if the index is a string, we don't want to add quotes around it
53+
if isinstance(index, str):
54+
json_index = index
55+
else:
56+
json_index = json.dumps(index, cls=NpEncoder)
5457
formatted_result[column_id][json_index] = {'backgroundColor': backgroundColor, 'color': color}
5558

5659
except Exception as e:

mitosheet/mitosheet/tests/test_column_definitions.py mitosheet/mitosheet/tests/streamlit/test_column_definitions.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import pytest
23
from mitosheet.mito_backend import MitoBackend, get_mito_backend
34
import pandas as pd
@@ -233,7 +234,28 @@ def test_create_backend_with_column_definitions_does_not_error_with_mismatch_con
233234
assert df_formats[0]['conditional_formats'][0]['invalidFilterColumnIDs'] == []
234235

235236

237+
def test_column_definitions_with_string_indexes_conditional_format_works():
238+
column_definitions= [
239+
[
240+
{
241+
'columns': ['A'],
242+
'conditional_formats': [{
243+
'filters': [{'condition': 'number_exactly', 'value': 2}],
244+
'font_color': '#c30010',
245+
'background_color': '#ffcbd1'
246+
}]
247+
}
248+
]
249+
]
250+
236251

252+
mito_backend = get_mito_backend(pd.DataFrame({'A': [1, 2, 3]}, index=['S1', 'S2', 'S3']), column_definitions=column_definitions)
253+
sheet_json = mito_backend.get_shared_state_variables()['sheet_data_json']
254+
sheet_data = json.loads(sheet_json)[0]
255+
conditional_formatting_result = sheet_data['conditionalFormattingResult']
256+
assert len(conditional_formatting_result['results']) == 1
257+
assert len(conditional_formatting_result['results']['A']) == 1
258+
assert 'S2' in conditional_formatting_result['results']['A']
237259

238260

239261

0 commit comments

Comments
 (0)