Skip to content

Commit d4f9f81

Browse files
committed
where_ adjustment
1 parent 395cdcb commit d4f9f81

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/seekwellpandas/methods.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ def _process_column(col, all_columns, selected_columns, excluded_columns):
5757
else:
5858
selected_columns.add(col)
5959

60-
@pf.register_dataframe_method
61-
import pandas as pd
62-
import pandas_flavor as pf
63-
import re
64-
65-
@pf.register_dataframe_method
66-
import pandas as pd
67-
import pandas_flavor as pf
68-
import re
69-
70-
@pf.register_dataframe_method
71-
import pandas as pd
72-
import pandas_flavor as pf
73-
import re
74-
7560
@pf.register_dataframe_method
7661
def where_(df, condition):
7762
"""
@@ -88,21 +73,24 @@ def where_(df, condition):
8873
df.where_('column > 5')
8974
df.where_('column in Adelie, Gentoo, Chinstrap')
9075
df.where_('column1 == value and column2 > 10')
91-
df.where_("sex == female and island == Torgersen")
76+
df.where_("sex == female and island == Dream")
9277
df.where_("(species in Adelie, Gentoo) & (body_mass_g > 3000)")
9378
df.where_("species not in Adelie or island == Torgersen")
9479
"""
9580
def parse_value(value):
81+
# Check if the value is already a string literal
9682
if value.startswith("'") and value.endswith("'"):
9783
return value
84+
# Try to convert to float or int
9885
try:
9986
return float(value) if '.' in value else int(value)
10087
except ValueError:
88+
# If conversion fails, treat as string and add quotes
10189
return f"'{value}'"
10290

10391
def parse_in_condition(column, values):
10492
parsed_values = [parse_value(v.strip()) for v in values.split(',')]
105-
return f"{column}.isin([{', '.join(parsed_values)}])"
93+
return f"{column}.isin([{', '.join(map(str, parsed_values))}])"
10694

10795
def parse_condition(cond):
10896
# Handle 'in' and 'not in' conditions

0 commit comments

Comments
 (0)