Skip to content

Commit

Permalink
refactor!: Remove utils.pair_plot function (#92)
Browse files Browse the repository at this point in the history
The function is a single line and does not belong in `utils` module.
Moved the implementation directly to the only place where it is called:
`edvart.bivariate_analysis.PairPlot`.

BREAKING CHANGE: The function `utils.pair_plot` is removed.
  • Loading branch information
mbelak-dtml authored Sep 7, 2023
1 parent 3c33b6e commit 81570b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
4 changes: 2 additions & 2 deletions edvart/report_sections/bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def include_column(col: str) -> bool:
if not allow_categorical:
columns_x = list(filter(include_column, columns_x))
columns_y = list(filter(include_column, columns_y))
utils.pair_plot(df, columns_x, columns_y, color_col=color_col)
sns.pairplot(df, x_vars=columns_x, y_vars=columns_y, hue=color_col)
plt.tight_layout()
plt.show()

Expand All @@ -690,9 +690,9 @@ def required_imports(self) -> List[str]:
)
]
return [
"from edvart import utils",
"from edvart.data_types import is_categorical, is_boolean",
"import matplotlib.pyplot as plt",
"import seaborn as sns",
]

def add_cells(self, cells: List[Dict[str, Any]]) -> None:
Expand Down
27 changes: 1 addition & 26 deletions edvart/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import os
from contextlib import contextmanager
from typing import Any, Dict, Iterable, Iterator, List, Literal, Optional, Tuple, Union
from typing import Any, Dict, Iterable, Iterator, Literal, Optional, Tuple, Union

import pandas as pd
import seaborn as sns
import statsmodels.api as sm


Expand Down Expand Up @@ -482,30 +481,6 @@ def _corr(df: pd.DataFrame, method: Literal["pearson", "kendall", "spearman"]) -
return df.corr(method=method, numeric_only=True)


def pair_plot(
df: pd.DataFrame,
columns_x: Optional[List[str]] = None,
columns_y: Optional[List[str]] = None,
color_col: Optional[str] = None,
) -> None:
"""
Plot a pairplot.
Parameters
----------
df: pd.DataFrame
DataFrame used for pairplot
columns_x: List[str], optional
List of columns to plot on the x-axis.
columns_y : List[str], optional
List of columns to plot on the y-axis.
color_col : str, optional
Name of columns according to which to color points in the pairplot and univariate
distribution plots on the diagonals.
"""
sns.pairplot(df, x_vars=columns_x, y_vars=columns_y, hue=color_col)


def contingency_table(df: pd.DataFrame) -> pd.DataFrame:
"""
Return contingency table.
Expand Down

0 comments on commit 81570b1

Please sign in to comment.