-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
WARN: Add FutureWarning to DataFrame.to_html
#44451
Changes from 28 commits
2fa2246
89225de
1119a27
93d9288
2e653fe
8e10574
e4fa4ef
e20c5d9
e6fc67e
310bdc2
3524116
43acc91
f41a438
ad8cf24
0d5b4b3
bd5e91c
7e3c3df
7de29d1
f2a944a
5f4d55c
6a4523e
9e66a72
505953d
d859877
02d913c
7d5ab6c
a9e4ac4
ee97624
10a34cb
272670a
3af20b6
6962393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,7 @@ column names and dtypes. That's because Dask hasn't actually read the data yet. | |
Rather than executing immediately, doing operations build up a **task graph**. | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated? (if so, can you remove it again) |
||
ddf | ||
ddf["name"] | ||
|
@@ -333,6 +334,7 @@ known automatically. In this case, since we created the parquet files manually, | |
we need to supply the divisions manually. | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
N = 12 | ||
starts = [f"20{i:>02d}-01-01" for i in range(N)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2908,8 +2908,55 @@ def to_html( | |
%(returns)s | ||
See Also | ||
-------- | ||
Styler.to_html : Render a DataFrame to HTML with conditional formatting. | ||
to_string : Convert DataFrame to a string. | ||
""" | ||
# Warnings are shown in 1.4.0 in preparation for signature changes in 2.0.0 | ||
warnings_default_none = { | ||
"classes": "replaced by `table_attributes`", | ||
"sparsify": "replaced by `sparse_index` and `sparse_columns`", | ||
"max_cols": "replaced by `max_columns` for consistency", | ||
"formatters": "replaced by `formatter` accepted by `Styler.format`", | ||
"float_format": "replaced by `precision`, `decimal`, and `thousands`", | ||
"border": "removed as deprecated HTML, suggested to use CSS", | ||
"col_space": "removed, suggested to use CSS `min-width: 100px;`", | ||
"justify": "removed, suggested to use CSS", | ||
} | ||
|
||
warnings_default_false = { | ||
"render_links": "removed due to limited functionality", | ||
"notebook": "removed as a legacy argument", | ||
"show_dimensions": "removed, suggested to use `caption=f'{df.shape}'`", | ||
} | ||
|
||
warnings_default_true = { | ||
"bold_rows": "replaced by `bold_headers` controlling index and columns", | ||
} | ||
|
||
warning_msg = ( | ||
"In future versions `DataFrame.to_html` is expected to utilise the base " | ||
"implementation of `Styler.to_html` for formatting and rendering. " | ||
"The arguments signature may therefore change. You are specifically using " | ||
"the following arguments: " | ||
) | ||
warning_flag = False | ||
|
||
for kwarg, msg in warnings_default_none.items(): | ||
if locals()[kwarg] is not None: | ||
warning_flag = True | ||
warning_msg += f"\n `{kwarg}`, which may be {msg}." | ||
for kwarg, msg in warnings_default_false.items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For those cases where the default is not None (but True or False), we will also need to raise a deprecation warning if the user specified the keyword explicitly but with the default (as that will also stop working if the keyword is removed in the future). |
||
if locals()[kwarg] is True: | ||
warning_flag = True | ||
warning_msg += f"\n `{kwarg}`, which may be {msg}." | ||
for kwarg, msg in warnings_default_true.items(): | ||
if locals()[kwarg] is False: | ||
warning_flag = True | ||
warning_msg += f"\n `{kwarg}`, which may be {msg}." | ||
|
||
if warning_flag: | ||
warnings.warn(warning_msg, FutureWarning, stacklevel=find_stack_level()) | ||
|
||
if justify is not None and justify not in fmt._VALID_JUSTIFY_PARAMETERS: | ||
raise ValueError("Invalid value for justify parameter") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
|
||
import pandas.io.formats.format as fmt | ||
|
||
pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this actually filtering out all warnings? that's the thing, how do we know this is not warning when it shouldn't be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that filters the generic warnings but the tests added, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make the filter a bit more specific? (eg match the beginning of the message) Just to ensure we only ignore this warning, and not accidentally suppress warnings we should see. |
||
|
||
lorem_ipsum = ( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " | ||
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | ||
|
@@ -872,3 +874,50 @@ def test_to_html_float_format_object_col(datapath): | |
result = df.to_html(float_format=lambda x: f"{x:,.0f}") | ||
expected = expected_html(datapath, "gh40024_expected_output") | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"kw1, kw1_val, kw1_msg", | ||
[ | ||
("classes", "text", "replaced by `table_attributes`"), | ||
("sparsify", True, "replaced by `sparse_index` and `sparse_columns`"), | ||
("max_cols", 1, "replaced by `max_columns` for consistency"), | ||
("formatters", [None], "replaced by `formatter` accepted by `Styler.format`"), | ||
("float_format", "txt", "replaced by `precision`, `decimal`, and `thousands`"), | ||
("border", 10, "removed as deprecated HTML, suggested to use CSS"), | ||
("col_space", 1, "removed, suggested to use CSS `min-width: 100px;`"), | ||
("justify", "right", "removed, suggested to use CSS"), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"kw2, kw2_val, kw2_msg", | ||
[ | ||
("render_links", True, "removed due to limited functionality"), | ||
("notebook", True, "removed as a legacy argument"), | ||
("show_dimensions", True, "removed, suggested to use `caption=f'{df.shape}'`"), | ||
( | ||
"bold_rows", | ||
False, | ||
"replaced by `bold_headers` controlling index and columns", | ||
), | ||
], | ||
) | ||
def test_future_warning(kw1, kw1_val, kw1_msg, kw2, kw2_val, kw2_msg): | ||
df = DataFrame([[1]]) | ||
msg = ( | ||
"In future versions `DataFrame.to_html` is expected to utilise the base " | ||
"implementation of `Styler.to_html` for formatting and rendering. " | ||
"The arguments signature may therefore change. You are specifically using " | ||
"the following arguments: " | ||
) | ||
msg += f"\\n `{kw1}`, which may be {kw1_msg}." | ||
msg += f"\\n `{kw2}`, which may be {kw2_msg}." | ||
|
||
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
df.to_html(**{kw1: kw1_val, kw2: kw2_val}) | ||
|
||
|
||
def test_no_future_warning(): | ||
df = DataFrame([[1]]) | ||
with tm.assert_produces_warning(None): | ||
df.to_html() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the sphinx cross-reference syntax instead of the path-based link? (
:meth:`Styler.to_html() <pandas.io.formats.style.Styler.to_html>`
for the long format and controlling which text is changes, but I think in this case you can also use:meth:`.Styler.to_html`
to get exactly the same)(and the same for similar cases below)