Skip to content

Commit f0a9008

Browse files
Added relevant tests when removing single quotes
1 parent a13b8b1 commit f0a9008

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

pandas/tests/io/formats/test_printing.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22
# functions, not the general printing of pandas objects.
33
from collections.abc import Mapping
44
import string
5-
5+
import ast
66
import pandas._config.config as cf
7-
7+
import pandas as pd
88
from pandas.io.formats import printing
99

1010

11+
def test_formatted_index_names():
12+
# Test cases: (input index names, expected formatted index names as lists)
13+
test_cases = [
14+
(["'a", "b"], ['a', 'b']), # Remove leading quote
15+
(["test's", "b"], ['tests', 'b']), # Remove apostrophe
16+
(["'test'", "b"], ['test', 'b']), # Remove surrounding quotes
17+
(["test","'b"], ["test",'b']), # Remove single quote
18+
(["'test\n'", "b"], ['test\n', 'b']) # Remove quotes, preserve newline
19+
]
20+
21+
for input_names, expected_names in test_cases:
22+
# Create DataFrame with specified index names
23+
df = pd.DataFrame({name: [1, 2, 3] for name in input_names}).set_index(input_names)
24+
index_names_str = df.index.names.__str__()
25+
26+
formatted_names = ast.literal_eval(index_names_str)
27+
28+
# Compare the formatted names with the expected names
29+
assert formatted_names == expected_names
30+
31+
1132
def test_adjoin():
1233
data = [["a", "b", "c"], ["dd", "ee", "ff"], ["ggg", "hhh", "iii"]]
1334
expected = "a dd ggg\nb ee hhh\nc ff iii"

0 commit comments

Comments
 (0)