Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INVESTIGATION] mitosheet: optimize out unneeded code after deletes #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions mitosheet/mitosheet/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,43 @@ def final_defined_state(self) -> State:
"""
return self.post_state if self.post_state is not None else \
(self.prev_state if self.prev_state is not None else State([]))

@property
def new_sheet_indexes_this_step(self) -> Set[int]:
"""
Returns the set of sheet indexes for sheets that were created
during this step. This is useful for depedency detection
"""
if self.prev_state is None:
return {i for i in range(len(self.post_state.dfs))}

if self.post_state is None:
return {}

return {
i for i in range(
len(self.prev_state.dfs),
len(self.post_state.dfs)
)
}

@property
def input_sheet_indexes(self) -> Set[int]:
"""
TODO
"""
return self.step_performer.get_input_dataframe_indexes(
**self.params
)

@property
def output_sheet_indexes(self) -> Set[int]:
"""
TODO
"""
return self.step_performer.get_output_dataframe_indexes(
**self.params
)

def set_prev_state_and_execute(self, new_prev_state: State) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ def describe(
return f'Renamed headers for compatibility with previous Mito versions'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_output_dataframe_indexes( # type: ignore
cls,
**params
) -> Set[int]:
return {-1}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
**params
) -> Set[int]:
Expand Down
12 changes: 11 additions & 1 deletion mitosheet/mitosheet/step_performers/column_steps/add_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,17 @@ def describe( # type: ignore
return f'Added column {column_header}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_header: str,
column_header_index: int,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_header: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,18 @@ def describe( # type: ignore
return f'Changed {column_id} from {old_dtype} to {new_dtype}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
old_dtype: str,
new_dtype: str,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ def describe( # type: ignore
return f'Formatted column{"s" if len(column_ids) > 1 else ""} {formated_column_ids} as {format_type["type"]}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ def describe( # type: ignore
return f'Deleted column{"s" if len(column_ids) > 1 else ""} {formated_column_ids}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,18 @@ def describe( # type: ignore
return f'Renamed header at level {level} to {new_column_header}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
new_column_header: str,
level=None,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ def describe( # type: ignore
return f'Reordered {column_id}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
new_column_index: int,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ def describe( # type: ignore
return f'Set {column_id} to {new_formula}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
old_formula: str,
new_formula: str,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ def describe( # type: ignore
return f'Deleted dataframe {old_dataframe_name}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
old_dataframe_name: str,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
old_dataframe_name: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,17 @@ def describe( # type: ignore
new_df_name = df_names[len(df_names) - 1]
return f'Duplicated {old_df_name} to {new_df_name}'
return f'Duplicated a df'

@classmethod
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
**params
) -> Set[int]:
return {}

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
**params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ def describe( # type: ignore
return f'Renamed {old_dataframe_name} to {new_dataframe_name}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
old_dataframe_name: str,
new_dataframe_name: str,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
old_dataframe_name: str,
Expand Down
12 changes: 11 additions & 1 deletion mitosheet/mitosheet/step_performers/drop_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ def describe( # type: ignore
return f'Drop duplicates'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
keep: str,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_ids: List[ColumnID],
Expand Down
13 changes: 12 additions & 1 deletion mitosheet/mitosheet/step_performers/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,18 @@ def describe( # type: ignore
return f'Filtered {column_id}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
operator: str,
filters,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
13 changes: 12 additions & 1 deletion mitosheet/mitosheet/step_performers/import_steps/excel_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,18 @@ def describe( # type: ignore
return f'Imported {file_name}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
file_name: str,
sheet_names: List[str],
has_headers: bool,
use_deprecated_id_algorithm: bool=False,
**params
) -> Set[int]:
return {}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
file_name: str,
sheet_names: List[str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ def describe( # type: ignore
return f'Imported {", ".join(file_names)}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
file_names: List[str],
use_deprecated_id_algorithm: bool=False,
**params
) -> Set[int]:
return {}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
file_names: List[str],
use_deprecated_id_algorithm: bool=False,
Expand Down
15 changes: 14 additions & 1 deletion mitosheet/mitosheet/step_performers/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,20 @@ def describe( # type: ignore
return f'Merged dataframes {sheet_index_one} and {sheet_index_two}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
how: str,
sheet_index_one: int,
merge_key_column_id_one: ColumnID,
selected_column_ids_one: List[ColumnID],
sheet_index_two: int,
merge_key_column_id_two: ColumnID,
selected_column_ids_two: List[ColumnID],
) -> Set[int]:
return {sheet_index_one, sheet_index_two}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
how: str,
sheet_index_one: int,
Expand Down
17 changes: 15 additions & 2 deletions mitosheet/mitosheet/step_performers/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,22 @@ def describe( # type: ignore
old_df_name = df_names[sheet_index]
return f'Pivoted {old_df_name} into {new_df_name}'
return f'Pivoted dataframe {sheet_index}'


@classmethod
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index,
pivot_rows_column_ids,
pivot_columns_column_ids,
values_column_ids_map,
destination_sheet_index=None,
use_deprecated_id_algorithm: bool=False,
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index,
pivot_rows_column_ids,
Expand Down
14 changes: 13 additions & 1 deletion mitosheet/mitosheet/step_performers/set_cell_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,19 @@ def describe( # type: ignore
return f'Set column {column_id} at index {row_index} to {new_value}'

@classmethod
def get_modified_dataframe_indexes( # type: ignore
def get_input_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
row_index: int,
old_value: str,
new_value: Union[str, None],
**params
) -> Set[int]:
return {sheet_index}

@classmethod
def get_output_dataframe_indexes( # type: ignore
cls,
sheet_index: int,
column_id: ColumnID,
Expand Down
Loading