This repository was archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
fix: Perform the last action with the column name modified. #9
Open
tashiro-akira
wants to merge
22
commits into
sapientml:main
Choose a base branch
from
tashiro-akira:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
55786bc
fix: Fix error caused when input data is mixed with datetime and stri…
5466bed
fix: Fix error caused when input data is mixed with datetime and stri…
f4807c2
fix: Fix error caused when input data is mixed with datetime and stri…
99a9d7e
fix:Modifying Source Code Formatting
e951d23
Merge branch 'sapientml:main' into main
tashiro-akira 812da98
fix:Reflect Review
937880c
fix: Remove Unnecessary Imports
79e39e3
fix: Reflect the point
22e0080
Merge branch 'sapientml:main' into main
tashiro-akira edd4d49
fix:Reflected review results
e063795
style:Modified to fit the format
22be366
fix:Fixed to return column names in csv file
3b62abb
fix:Reflected the content of the review
ce996da
Merge branch 'sapientml:main' into main
tashiro-akira 9ea7ad3
Merge branch 'sapientml:main' into main
tashiro-akira 6433d99
fix:Reflected review results
bed2b88
Merge branch 'sapientml:main' into main
tashiro-akira e1da54c
fix:Reflect Review Results
tashiro-akira 895d5c4
Merge branch 'main' of https://github.com/tashiro-akira/preprocess_ta…
tashiro-akira bde5ad9
fix:Fixed error in running lint
tashiro-akira 8c15e21
fix:Reflect Review Results
tashiro-akira 1f62efd
fix:Reflect Review Results
tashiro-akira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import collections | ||
| import os | ||
| import re | ||
| from pathlib import Path | ||
|
|
@@ -31,7 +32,7 @@ | |
|
|
||
| logger = setup_logger() | ||
|
|
||
| INHIBITED_SYMBOL_PATTERN = re.compile(r"[\{\}\[\]\",:<'\\]+") | ||
| INHIBITED_SYMBOL_PATTERN = re.compile(r"[\{\}\[\]\",:<'\\\+]+") | ||
|
|
||
|
|
||
| template_env = Environment(loader=FileSystemLoader(f"{os.path.dirname(__file__)}/templates"), trim_blocks=True) | ||
|
|
@@ -229,15 +230,46 @@ def generate_code(self, dataset: Dataset, task: Task) -> Tuple[Dataset, Code]: | |
| logger.warning( | ||
| f"Symbols that inhibit training and visualization will be removed from column name {str(cols_has_symbols)}." | ||
| ) | ||
| org_df_column = df.columns.values | ||
| org_target_column = task.target_columns | ||
| df = df.rename(columns=lambda col: remove_symbols(col) if col in cols_has_symbols else col) | ||
| task.target_columns = [ | ||
| remove_symbols(col) if col in cols_has_symbols else col for col in task.target_columns | ||
| ] | ||
| same_column = {k: v for k, v in collections.Counter(list(df.columns.values)).items() if v > 1} | ||
| rename_dict = {} | ||
| if len(same_column) != 0: | ||
| for target in same_column.keys(): | ||
| rename_dict = {} | ||
| rename_target_col = [] | ||
| df_cols = list(df.columns.values) | ||
| i = 1 | ||
| for col in df_cols: | ||
| if target in col: | ||
| rename_dict[org_df_column[len(rename_dict)]] = str(col + str(i)) | ||
| i = i + 1 | ||
| else: | ||
| rename_dict[org_df_column[len(rename_dict)]] = col | ||
| df = df.set_axis(list(rename_dict.values()), axis=1) | ||
| i = 1 | ||
| for col in org_target_column: | ||
| rename_target_col.append(rename_dict[col]) | ||
|
|
||
| task.target_columns = rename_target_col | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The review has been applied. |
||
| tpl = template_env.get_template("rename_columns.py.jinja") | ||
| code.validation += _render(tpl, training=True, test=True, cols_has_symbols=cols_has_symbols) | ||
| code.test += _render(tpl, training=True, test=True, cols_has_symbols=cols_has_symbols) | ||
| code.train += _render(tpl, training=True, test=False, cols_has_symbols=cols_has_symbols) | ||
| code.predict += _render(tpl, training=False, test=True, cols_has_symbols=cols_has_symbols) | ||
| code.validation += _render( | ||
| tpl, training=True, test=True, cols_has_symbols=cols_has_symbols, rename_dict=rename_dict | ||
| ) | ||
| code.test += _render( | ||
| tpl, training=True, test=True, cols_has_symbols=cols_has_symbols, rename_dict=rename_dict | ||
| ) | ||
| code.train += _render( | ||
| tpl, training=True, test=False, cols_has_symbols=cols_has_symbols, rename_dict=rename_dict | ||
| ) | ||
| code.predict += _render( | ||
| tpl, training=False, test=True, cols_has_symbols=cols_has_symbols, rename_dict=rename_dict | ||
| ) | ||
|
|
||
| # handle list(tuple, dict) value in dataframe. | ||
| # in generated scripts, visualisation will be executed before pre-processing such as handle mixed-type. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| # Remove special symbols that interfere with visualization and model training | ||
| import re | ||
| cols_has_symbols = {{ cols_has_symbols }} | ||
| inhibited_symbol_pattern = re.compile(r"[\{\}\[\]\",:<'\\]+") | ||
| rename_dict = {{ rename_dict }} | ||
| inhibited_symbol_pattern = re.compile(r"[\{\}\[\]\",:<'\\\+]+") | ||
| if len(rename_dict) == 0 : | ||
| 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 } | ||
| else: | ||
| rename_symbol_cols = rename_dict | ||
|
||
| {% 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) | ||
| train_dataset = train_dataset.rename(columns=rename_symbol_cols) | ||
| {% endif %} | ||
| {% if test %} | ||
| test_dataset = test_dataset.rename(columns=lambda col: inhibited_symbol_pattern.sub("", col) if col in cols_has_symbols else col) | ||
| {% endif %} | ||
| test_dataset = test_dataset.rename(columns=rename_symbol_cols) | ||
| {% endif %} | ||
| rename_symbol_cols = {v: k for k, v in rename_symbol_cols.items()} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add
\+?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was checking if "+" is treated as a symbol in the test string.
I put it back.