Skip to content

Commit

Permalink
fix: comparison to_json pd.Series encoding error (#1538)
Browse files Browse the repository at this point in the history
* fix: comparison to_json pd.Series encoding error

* fix(linting): code formatting

* fix: unit test

* fix(linting): code formatting

---------

Co-authored-by: Azory YData Bot <[email protected]>
  • Loading branch information
alexbarros and azory-ydata authored Feb 9, 2024
1 parent cdfc17a commit 2d9a24b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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"
)

0 comments on commit 2d9a24b

Please sign in to comment.