Skip to content

Commit

Permalink
Python 3.5 support, tests for [ydataai#147] and XSS filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed May 30, 2019
1 parent 8809c45 commit d6c85be
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ target/
.ipynb_checkpoints/
ipynb_tmp/
examples/*/*.csv
examples/*/*.html
examples/*/*.html
*.parquet
5 changes: 3 additions & 2 deletions docs/view/formatters.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h1 class="title">Module <code>pandas_profiling.view.formatters</code></h1>
<details class="source">
<summary>Source code</summary>
<pre><code class="python">&#34;&#34;&#34;Formatters are utilities for formatting numbers and certain strings&#34;&#34;&#34;
from jinja2.utils import escape


def fmt_color(text: str, color: str) -&gt; str:
Expand Down Expand Up @@ -107,7 +108,7 @@ <h1 class="title">Module <code>pandas_profiling.view.formatters</code></h1>
if type(value) in [float, int]:
return fmt_numeric(value)
else:
return str(value)
return str(escape(value))


def hex_to_rgb(hex):
Expand Down Expand Up @@ -159,7 +160,7 @@ <h2 id="returns">Returns</h2>
if type(value) in [float, int]:
return fmt_numeric(value)
else:
return str(value)</code></pre>
return str(escape(value))</code></pre>
</details>
</dd>
<dt id="pandas_profiling.view.formatters.fmt_bytesize"><code class="name flex">
Expand Down
3 changes: 2 additions & 1 deletion pandas_profiling/view/formatters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Formatters are utilities for formatting numbers and certain strings"""
from jinja2.utils import escape


def fmt_color(text: str, color: str) -> str:
Expand Down Expand Up @@ -82,7 +83,7 @@ def fmt(value) -> str:
if type(value) in [float, int]:
return fmt_numeric(value)
else:
return str(value)
return str(escape(value))


def hex_to_rgb(hex):
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest
codecov
pytest-cov
nbval
pyarrow
20 changes: 20 additions & 0 deletions tests/issues/test_issue147.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

import pandas as pd
import requests

from pandas_profiling import ProfileReport


# https://github.com/pandas-profiling/pandas-profiling/issues/147
def test_issue147(tmpdir):
file_name = Path(str(tmpdir)) / "userdata1.parquet"
data = requests.get(
"https://github.com/Teradata/kylo/raw/master/samples/sample-data/parquet/userdata2.parquet"
)
file_name.write_bytes(data.content)

df = pd.read_parquet(str(file_name), engine="pyarrow")
report = ProfileReport(df, title="PyArrow with Pandas Parquet Backend")
html = report.to_html()
assert type(html) == str and '<p class="h2">Dataset info</p>' in html
33 changes: 29 additions & 4 deletions tests/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,20 @@ def recoding_data():

def test_recoding_reject(recoding_data):
results = describe(recoding_data)
assert results["variables"]["y"]["type"] == Variable.S_TYPE_RECODED, "Type is wrong"
assert results["variables"]["y"]["correlation_var"] == "x", "Values should be equal"
assert (
results["variables"]["y"]["type"] == Variable.S_TYPE_RECODED
and results["variables"]["x"]["type"] == Variable.TYPE_CAT
) or (
results["variables"]["x"]["type"] == Variable.S_TYPE_RECODED
and results["variables"]["y"]["type"] == Variable.TYPE_CAT
), "Type is wrong"
assert (
"correlation_var" in results["variables"]["y"]
and results["variables"]["y"]["correlation_var"] == "x"
) or (
"correlation_var" in results["variables"]["x"]
and results["variables"]["x"]["correlation_var"] == "y"
), "Values should be equal"

expected_results = {
"n_cells_missing": 0.0,
Expand Down Expand Up @@ -89,8 +101,21 @@ def test_cramers_reject(recoding_data):
config["correlations"]["cramers"].set(True)
results = describe(recoding_data)

assert results["variables"]["y"]["type"] == Variable.S_TYPE_CORR, "Type is wrong"
assert results["variables"]["y"]["correlation_var"] == "x", "Values should be equal"
# The order of dicts is not preserved in Python 3.5 and not guaranteed in Python 3.6
assert (
results["variables"]["y"]["type"] == Variable.S_TYPE_CORR
and results["variables"]["x"]["type"] == Variable.TYPE_CAT
) or (
results["variables"]["x"]["type"] == Variable.S_TYPE_CORR
and results["variables"]["y"]["type"] == Variable.TYPE_CAT
), "Type is wrong"
assert (
"correlation_var" in results["variables"]["y"]
and results["variables"]["y"]["correlation_var"] == "x"
) or (
"correlation_var" in results["variables"]["x"]
and results["variables"]["x"]["correlation_var"] == "y"
), "Values should be equal"

expected_results = {
"n_cells_missing": 0.0,
Expand Down

0 comments on commit d6c85be

Please sign in to comment.