Skip to content

Commit

Permalink
fix(eda):fix long name in missing heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglinpeng committed May 20, 2021
1 parent 99b86f2 commit f6cc399
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 5 additions & 7 deletions dataprep/eda/missing/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def render_missing_impact(itmdt: Intermediate, cfg: Config) -> Dict[str, Any]:
}


def render_heatmaps(df: Optional[pd.DataFrame], plot_width: int, plot_height: int) -> Figure:
def render_heatmaps(data: Optional[pd.DataFrame], plot_width: int, plot_height: int) -> Figure:
"""
Render missing heatmaps in to tabs
"""
Expand All @@ -379,8 +379,10 @@ def empty_figure() -> Figure:
fig.rect(x=0, y=0, width=0, height=0)
return fig

if df is not None:

if data is not None:
df = data.copy()
df.columns = list(map(cut_long_name, df.columns))
df.index = list(map(cut_long_name, df.index))
df = df.where(np.triu(np.ones(df.shape)).astype(np.bool)).T # pylint: disable=no-member

if df.size != 0:
Expand All @@ -392,10 +394,6 @@ def empty_figure() -> Figure:
df = df[df["x"] != df["y"]]
df = drop_null(df)

# in case of numerical column names
df["x"] = df["x"].apply(str)
df["y"] = df["y"].apply(str)

fig = Figure(
x_range=x_range,
y_range=y_range,
Expand Down
7 changes: 3 additions & 4 deletions dataprep/eda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ def relocate_legend(fig: Figure, loc: str) -> Figure:
return fig


def cut_long_name(name: str, max_len: int = 12) -> str:
def cut_long_name(name: str, max_len: int = 18) -> str:
"""If the name is longer than `max_len`,
cut it to `max_len` length and append "..."""

# Bug 136 Fixed
name = str(name)
if len(name) <= max_len:
return name
return f"{name[:max_len]}..."
cut_name = f"{name[:13]}...{name[len(name)-3:]}" if len(name) > max_len else name
return cut_name


def fuse_missing_perc(name: str, perc: float) -> str:
Expand Down

0 comments on commit f6cc399

Please sign in to comment.