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: comparison to_json pd.Series encoding error #1538

Merged
merged 4 commits into from
Feb 9, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/ydata_profiling/profile_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ def encode_it(o: Any) -> Any:
return [encode_it(v) for v in o]
elif isinstance(o, set):
return {encode_it(v) for v in o}
elif isinstance(o, (pd.DataFrame, pd.Series)):
elif isinstance(o, pd.Series):
return encode_it(o.to_list())
elif isinstance(o, pd.DataFrame):
return encode_it(o.to_dict(orient="records"))
elif isinstance(o, np.ndarray):
return encode_it(o.tolist())
Expand Down
34 changes: 34 additions & 0 deletions tests/issues/test_issue1529.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Test for issue 1529:
https://github.com/ydataai/ydata-profiling/issues/1529
"""
import json

import pandas as pd

from ydata_profiling import ProfileReport


def test_issue1529():
previous_dataset = pd.DataFrame(
data=[(1000, 42), (900, 30), (1500, 40), (1800, 38)],
columns=["rent_per_month", "total_area"],
)
current_dataset = pd.DataFrame(
data=[(5000, 350), (9000, 600), (5000, 400), (3500, 500), (6000, 600)],
columns=["rent_per_month", "total_area"],
)
previous_dataset_report = ProfileReport(
previous_dataset, title="Previous dataset report"
)
current_dataset_report = ProfileReport(
current_dataset, title="Current dataset report"
)
comparison_report = previous_dataset_report.compare(current_dataset_report)
json_str = comparison_report.to_json()
compare_dict = json.loads(json_str)
assert compare_dict is not None and len(compare_dict) > 0
assert (
compare_dict["analysis"]["title"]
== "<em>Comparing</em> Previous dataset report <em>and</em> Current dataset report"
)