6
6
7
7
8
8
from copy import copy
9
+ from datetime import date
9
10
from typing import List , Optional , Tuple , Union
10
11
11
12
from mitosheet .code_chunks .code_chunk import CodeChunk
25
26
get_column_header_as_transpiled_code , get_list_as_string_without_internal_quotes )
26
27
from mitosheet .types import (ColumnHeader , ColumnID , ColumnIDWithFilterGroup ,
27
28
Filter , FilterGroup , OperatorType )
29
+ import pandas as pd
28
30
29
31
# Dict used when a filter condition is only used by one filter
30
32
FILTER_FORMAT_STRING_DICT = {
180
182
OPERATOR_SIGNS = {"Or" : "|" , "And" : "&" }
181
183
182
184
def get_single_filter_string (
183
- df_name : str , column_header : ColumnHeader , filter_ : Filter
185
+ df_name : str , column_header : ColumnHeader , column_dtype : str , filter_ : Filter
184
186
) -> str :
185
187
"""
186
188
Transpiles a specific filter to a fitler string, to be used
@@ -189,6 +191,14 @@ def get_single_filter_string(
189
191
condition = filter_ ["condition" ]
190
192
value = filter_ ["value" ]
191
193
194
+ # When users are mid-way through typing a date in the UI, it might not be valid yet.
195
+ # To prevent throwing errors, we set it to the minimum date
196
+ if is_datetime_dtype (column_dtype ):
197
+ try :
198
+ pd .to_datetime (value )
199
+ except :
200
+ value = pd .Timestamp .min + pd .Timedelta (seconds = 1 )
201
+
192
202
transpiled_column_header = get_column_header_as_transpiled_code (column_header )
193
203
value = get_column_header_as_transpiled_code (value )
194
204
@@ -289,7 +299,7 @@ def create_filter_string_for_condition(
289
299
elif len (filters_with_condition ) == 1 :
290
300
# Use the single filter condition
291
301
return get_single_filter_string (
292
- df_name , column_header , filters_with_condition [0 ]
302
+ df_name , column_header , column_dtype , filters_with_condition [0 ]
293
303
)
294
304
elif len (filters_with_condition ) > 1 :
295
305
# Use the multiple filter condition
0 commit comments