Skip to content

fix: issue1688 is not None to avoid the error #1750

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/ydata_profiling/model/summary_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def histogram_compute(
bins = np.histogram_bin_edges(finite_values, bins=bins_arg)
if len(bins) > hist_config.max_bins:
bins = np.histogram_bin_edges(finite_values, bins=hist_config.max_bins)
weights = weights if weights and len(weights) == hist_config.max_bins else None
weights = (
weights
if (weights is not None and len(weights) == hist_config.max_bins)
else None
)

stats[name] = np.histogram(
finite_values, bins=bins, weights=weights, density=config.plot.histogram.density
Expand Down
60 changes: 60 additions & 0 deletions tests/issues/test_issue1688.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Test for issue 1688.

https://github.com/ydataai/ydata-profiling/issues/1688

"""
import tempfile

import numpy as np
import pandas as pd
import pytest

from ydata_profiling import ProfileReport
from ydata_profiling.config import Settings
from ydata_profiling.utils.paths import get_config


@pytest.fixture
def data():
"""Creates a dataframe for the test."""
data = [
[1.0, 999, "", 10, None],
[34.54, 3424, None, 4, 5],
[9548.43, 1, "fdsfv", 54, 876],
[32, 43.43, "dsfda", 43, 12],
[1.0, 5454, "cxcc", 13, 43],
[45.7, 43, "fsdfsfsfdsfsdf", 1, 54],
]

df = pd.DataFrame(np.array(data), columns=["a", "b", "c", "d", "e"])

return df


def test_empty_df(data):
"""Checking for an empty dataframe."""
if not len(data):
raise ValueError("Check the dataframe it is empty")


def test_issue1688(data):
"""
Check: empty_df, report and html.

Here, first the dataframe is checked to see if it is empty,
then a report and temporary html are created,
which is deleted after the block completes.
"""
test_empty_df(data)

conf = get_config("config_default.yaml")
conf = Settings().from_file(conf)
conf.plot.histogram.max_bins = 2
conf.plot.histogram.bins = 0
profile = ProfileReport(data, config=conf, title="Pandas Profiling Report")

with tempfile.NamedTemporaryFile(delete=True) as temp_file:
# Generate a temporary file and delete it
# after the block is completed
profile.to_file(temp_file.name)
Loading