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

fix: zero division for categorical colums with 100% missing data #1569

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ def length_summary_vc(vc: pd.Series) -> dict:

summary = {
"max_length": np.max(length_counts.index),
"mean_length": np.average(length_counts.index, weights=length_counts.values),
"mean_length": np.average(length_counts.index, weights=length_counts.values)
if not length_counts.empty
else np.nan,
"median_length": weighted_median(
length_counts.index.values, weights=length_counts.values
),
)
if not length_counts.empty
else np.nan,
"min_length": np.min(length_counts.index),
"length_histogram": length_counts,
}
Expand Down
4 changes: 4 additions & 0 deletions src/ydata_profiling/model/summary_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
weights: Optional[np.ndarray] = None,
) -> dict:
stats = {}
if len(finite_values) == 0:
return {name: []}

Check warning on line 38 in src/ydata_profiling/model/summary_algorithms.py

View check run for this annotation

Codecov / codecov/patch

src/ydata_profiling/model/summary_algorithms.py#L38

Added line #L38 was not covered by tests
hist_config = config.plot.histogram
bins_arg = "auto" if hist_config.bins == 0 else min(hist_config.bins, n_unique)
bins = np.histogram_bin_edges(finite_values, bins=bins_arg)
Expand All @@ -54,6 +56,8 @@
if histogram is None:
bins = np.histogram_bin_edges(values, bins="auto")
histogram, _ = np.histogram(values, bins=bins)
if len(histogram) == 0 or np.sum(histogram) == 0:
return {"statistic": 0, "pvalue": 0}

Check warning on line 60 in src/ydata_profiling/model/summary_algorithms.py

View check run for this annotation

Codecov / codecov/patch

src/ydata_profiling/model/summary_algorithms.py#L60

Added line #L60 was not covered by tests
return dict(chisquare(histogram)._asdict())


Expand Down
Loading