Skip to content

Commit 5246992

Browse files
authored
Merge pull request #1287 from mito-ds/dev
3/15/24
2 parents 4c31f60 + e7c2128 commit 5246992

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
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/public/v3/formatting.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pandas import DataFrame, ExcelWriter
88

99
from mitosheet.excel_utils import get_column_from_column_index
10-
from mitosheet.is_type_utils import is_float_dtype
10+
from mitosheet.is_type_utils import is_float_dtype, is_int_dtype
1111
from mitosheet.types import (
1212
FC_BOOLEAN_IS_FALSE, FC_BOOLEAN_IS_TRUE, FC_DATETIME_EXACTLY,
1313
FC_DATETIME_GREATER, FC_DATETIME_GREATER_THAN_OR_EQUAL, FC_DATETIME_LESS,
@@ -152,13 +152,15 @@ def add_number_formatting(
152152
for column_index in default_number_format_column_indexes:
153153
column_header = column_headers[column_index]
154154
dtype = str(df[column_header].dtype)
155-
if not is_float_dtype(dtype):
156-
continue
157-
158155
column = get_column_from_column_index(column_index)
159156
cell_range = f'{column}2:{column}{sheet.max_row}'
160-
for cell in sheet[cell_range]:
161-
cell[0].number_format = '#,##0.00'
157+
158+
if is_float_dtype(dtype):
159+
for cell in sheet[cell_range]:
160+
cell[0].number_format = '#,##0.00'
161+
if is_int_dtype(dtype):
162+
for cell in sheet[cell_range]:
163+
cell[0].number_format = '#,##0'
162164

163165
def add_header_formatting_to_excel_sheet(
164166
writer: ExcelWriter,

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

mitosheet/mitosheet/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def write_to_excel(
253253
sheet_name = get_df_name_as_valid_sheet_name(df_name)
254254

255255
# Write the dataframe to the sheet
256-
df.to_excel(writer, sheet_name, index=False)
256+
df.to_excel(writer, sheet_name=sheet_name, index=False)
257257

258258
# Add formatting to the sheet for pro users
259259
format = state.df_formats[sheet_index]

mitosheet/src/mito/components/endo/focusUtils.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
export const focusGrid = (containerDiv: HTMLDivElement | null | undefined): void => {
1919
if (containerDiv) {
20-
containerDiv.focus()
20+
containerDiv.focus({preventScroll: true})
2121
}
2222
}

0 commit comments

Comments
 (0)