-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Merged
rhshadrach
merged 23 commits into
pandas-dev:main
from
thedataninja1786:bugfix--pprint-embedded-quotes
Nov 29, 2024
Merged
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
42203a9
remove single quotes in index names when printing
thedataninja1786 5d9edbf
Removed trailing whitespace
thedataninja1786 5da2343
Removed trailing whitespaces
thedataninja1786 9519268
Merge branch 'main' into bugfix--pprint-embedded-quotes
thedataninja1786 a13b8b1
branch 'upstream/main' into bugfix--pprint-embedded-quotes
thedataninja1786 f0a9008
Added relevant tests when removing single quotes
thedataninja1786 0f1c9e5
Merge branch 'bugfix--pprint-embedded-quotes' of https://github.com/t…
thedataninja1786 9552a43
Refactor test_formatted_index_names to adhere with line-legth constra…
thedataninja1786 597e6c5
Merge remote-tracking branch 'upstream/main' into bugfix--pprint-embe…
thedataninja1786 2fa7eeb
Escape single quotes
thedataninja1786 034ad05
Merge branch 'main' into bugfix--pprint-embedded-quotes
thedataninja1786 c3aa8f0
Merge remote-tracking branch 'upstream/main' into bugfix--pprint-embe…
thedataninja1786 bdcbca1
Apply formatting and import sorting from pre-commit hooks
thedataninja1786 a6cad8d
Apply formatting and import sorting from pre-commit hooks
thedataninja1786 9d02418
Apply formatting and import sorting from pre-commit hooks
thedataninja1786 7e59bda
Merge branch 'bugfix--pprint-embedded-quotes' of https://github.com/t…
thedataninja1786 67fd773
Apply formatting and import sorting from pre-commit hooks
thedataninja1786 67ecd35
Merge remote-tracking branch 'upstream/main' into bugfix--pprint-embe…
thedataninja1786 8c41d9d
Update whatsnew
thedataninja1786 7a4c1ee
Merge remote-tracking branch 'upstream/main' into bugfix--pprint-embe…
thedataninja1786 2c3625a
Update whatsnew in v3.0.0.
thedataninja1786 6391b76
Update whatsnew in v3.0.0.
thedataninja1786 10df8b4
Converted tests for string comparisons
thedataninja1786 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,35 @@ | |
# functions, not the general printing of pandas objects. | ||
from collections.abc import Mapping | ||
import string | ||
|
||
import ast | ||
import pandas._config.config as cf | ||
|
||
import pandas as pd | ||
from pandas.io.formats import printing | ||
|
||
|
||
def test_formatted_index_names(): | ||
# Test cases: (input index names, expected formatted index names as lists) | ||
test_cases = [ | ||
(["'a", "b"], ['a', 'b']), # Remove leading quote | ||
(["test's", "b"], ['tests', 'b']), # Remove apostrophe | ||
(["'test'", "b"], ['test', 'b']), # Remove surrounding quotes | ||
(["test","'b"], ["test",'b']), # Remove single quote | ||
(["'test\n'", "b"], ['test\n', 'b']) # Remove quotes, preserve newline | ||
] | ||
|
||
for input_names, expected_names in test_cases: | ||
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 use |
||
# Create DataFrame with specified index names | ||
df = pd.DataFrame( | ||
{name: [1, 2, 3] for name in input_names} | ||
).set_index(input_names) | ||
index_names_str = df.index.names.__str__() | ||
|
||
formatted_names = ast.literal_eval(index_names_str) | ||
|
||
# Compare the formatted names with the expected names | ||
assert formatted_names == expected_names | ||
|
||
|
||
def test_adjoin(): | ||
data = [["a", "b", "c"], ["dd", "ee", "ff"], ["ggg", "hhh", "iii"]] | ||
expected = "a dd ggg\nb ee hhh\nc ff iii" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 believe this will make the output here:
be
['a', 'b']
. That is not correct.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.
What would be the desired behavior?
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.
The index names must be accurate, the first being
'a
. I would think['\'a', 'b']
.