-
-
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
BUG: remove single quotes in index names when printing #60251
base: main
Are you sure you want to change the base?
Changes from 11 commits
42203a9
5d9edbf
5da2343
9519268
a13b8b1
f0a9008
0f1c9e5
9552a43
597e6c5
2fa7eeb
034ad05
c3aa8f0
bdcbca1
a6cad8d
9d02418
7e59bda
67fd773
67ecd35
8c41d9d
7a4c1ee
2c3625a
6391b76
10df8b4
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 |
---|---|---|
|
@@ -2,12 +2,29 @@ | |
# functions, not the general printing of pandas objects. | ||
from collections.abc import Mapping | ||
import string | ||
|
||
import pytest | ||
import pandas._config.config as cf | ||
|
||
import pandas as pd | ||
from pandas.io.formats import printing | ||
|
||
|
||
@pytest.mark.parametrize("input_names, expected_names", [ | ||
(["'a", "b"], ["\'a", "b"]), # Escape leading quote | ||
(["test's", "b"], ["test\'s", "b"]), # Escape apostrophe | ||
(["'test'", "b"], ["\'test\'", "b"]), # Escape surrounding quotes | ||
(["test","b'"], ["test","b\'"]), # Escape single quote | ||
(["'test\n'", "b"], ["\'test\n\'", "b"]) # Escape and preserve newline | ||
]) | ||
def test_formatted_index_names(input_names, expected_names): | ||
# Create DataFrame with specified index names | ||
df = pd.DataFrame( | ||
{name: [1, 2, 3] for name in input_names} | ||
).set_index(input_names) | ||
formatted_names = df.index.names | ||
|
||
assert formatted_names == expected_names | ||
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 test passes on the main branch, so is not testing your changes. You can do 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. 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. When comparing to 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. Just to clarify my previous comment, you cannot compare single entries because with a backslash (this PR) and without a backslash (main) evaluate as equal. However if you convert the entire input_names = ["'a", "b"]
df = pd.DataFrame({name: [1, 2, 3] for name in input_names}).set_index(input_names)
print(str(df.index.names) == "['\\'a', 'b']") # main
# False
print(str(df.index.names) == "['\\'a', 'b']") # PR
# True 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. Okay I think I'm with you :) |
||
|
||
|
||
def test_adjoin(): | ||
data = [["a", "b", "c"], ["dd", "ee", "ff"], ["ggg", "hhh", "iii"]] | ||
expected = "a dd ggg\nb ee hhh\nc ff iii" | ||
|
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 remove this comment - it repeats the code verbatim and so is not needed.
In addition, can you start the test with a comment referencing the issue:
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.
I think we are there now?