Skip to content

Commit

Permalink
refactor: Use direct conversion to represent inferred data type.
Browse files Browse the repository at this point in the history
Replaces two calls to `infer_data_type`, once with `string_representation=True` and
once with `string_representation=False`.
  • Loading branch information
mbelak-dtml committed Aug 31, 2023
1 parent 2ac7a3e commit 131f18c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,9 @@ def data_types(df: pd.DataFrame, columns: Optional[List[str]] = None) -> None:
if columns is not None:
df = df[columns]
dtypes = df.apply(
func=infer_data_type,
func=lambda x_: str(infer_data_type(x_)),
axis=0,
result_type="expand",
string_representation=True,
)

# Convert result to frame for viewing
Expand Down
6 changes: 3 additions & 3 deletions edvart/report_sections/univariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def univariate_analysis(df: pd.DataFrame, columns: Optional[List[str]] = None) -
display(Markdown(f"## *{col} - NULL*"))
display(Markdown("The column contains only null values."))
continue
data_type_name = infer_data_type(df[col], string_representation=True)
data_type = infer_data_type(df[col])
data_type_name = str(data_type)
display(Markdown(f"## *{col} - {data_type_name}*"))
if data_type in (DataType.CATEGORICAL, DataType.BOOLEAN):
UnivariateAnalysis.top_most_frequent(df[col])
Expand Down Expand Up @@ -375,8 +375,8 @@ def add_cells(self, cells: List[Dict[str, Any]]) -> None:
display(Markdown(f"## *{col} - NULL*"))
display(Markdown("The column contains only null values."))
continue
data_type_name = infer_data_type(self.df[col], string_representation=True)
data_type = infer_data_type(self.df[col])
data_type_name = str(data_type)
column_header = nbfv4.new_markdown_cell(f"## *{col} - {data_type_name}*")
cells.append(column_header)
if data_type in (DataType.CATEGORICAL, DataType.BOOLEAN):
Expand Down Expand Up @@ -429,8 +429,8 @@ def show(self, df: pd.DataFrame) -> None:
display(Markdown(f"## *{col} - NULL*"))
display(Markdown("The column contains only null values."))
continue
data_type_name = infer_data_type(df[col], string_representation=True)
data_type = infer_data_type(df[col])
data_type_name = str(data_type)
display(Markdown(f"## *{col} - {data_type_name}*"))
if data_type in (DataType.CATEGORICAL, DataType.BOOLEAN):
UnivariateAnalysis.top_most_frequent(df[col])
Expand Down

0 comments on commit 131f18c

Please sign in to comment.