Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions sapientml_preprocess/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,30 +271,10 @@ def generate_code(self, dataset: Dataset, task: Task) -> Tuple[Dataset, Code]:
df = df.drop(col, axis=1)
if cols_numeric_and_string:
tpl = template_env.get_template("handle_mixed_typed_columns.py.jinja")
code.validation += _render(
tpl,
training=True,
test=True,
cols_numeric_and_string=cols_numeric_and_string
)
code.test += _render(
tpl,
training=True,
test=True,
cols_numeric_and_string=cols_numeric_and_string
)
code.train += _render(
tpl,
training=True,
test=False,
cols_numeric_and_string=cols_numeric_and_string
)
code.predict += _render(
tpl,
training=False,
test=True,
cols_numeric_and_string=cols_numeric_and_string
)
code.validation += _render(tpl, training=True, test=True, cols_numeric_and_string=cols_numeric_and_string)
code.test += _render(tpl, training=True, test=True, cols_numeric_and_string=cols_numeric_and_string)
code.train += _render(tpl, training=True, test=False, cols_numeric_and_string=cols_numeric_and_string)
code.predict += _render(tpl, training=False, test=True, cols_numeric_and_string=cols_numeric_and_string)

# meta features must be calculated after replacing inf with nan,
# becuase the replaced nan must be preprocessed in the generated code.
Expand Down
2 changes: 2 additions & 0 deletions sapientml_preprocess/templates/rename_columns.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import re
cols_has_symbols = {{ cols_has_symbols }}
inhibited_symbol_pattern = re.compile(r"[\{\}\[\]\",:<'\\]+")
{% if training %}
rename_symbol_cols = {col: inhibited_symbol_pattern.sub("", col) if col in cols_has_symbols else col in cols_has_symbols for col in cols_has_symbols }
rename_symbol_cols = {v: k for k, v in rename_symbol_cols.items()}
train_dataset = train_dataset.rename(columns=lambda col: inhibited_symbol_pattern.sub("", col) if col in cols_has_symbols else col)
{% endif %}
{% if test %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following code?

rename_symbol_cols = {col: inhibited_symbol_pattern.sub("", col) if col in cols_has_symbols else col in cols_has_symbols for col in cols_has_symbols }
{% if training %}
train_dataset = train_dataset.rename(columns=rename_symbol_cols)
{% endif %}
{% if test %}
test_dataset = test_dataset.rename(columns=rename_symbol_cols)
{% endif %}
rename_symbol_cols = {v: k for k, v in rename_symbol_cols.items()}

Expand Down