|
2 | 2 | # functions, not the general printing of pandas objects.
|
3 | 3 | from collections.abc import Mapping
|
4 | 4 | import string
|
5 |
| - |
| 5 | +import ast |
6 | 6 | import pandas._config.config as cf
|
7 |
| - |
| 7 | +import pandas as pd |
8 | 8 | from pandas.io.formats import printing
|
9 | 9 |
|
10 | 10 |
|
| 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 | + |
11 | 32 | def test_adjoin():
|
12 | 33 | data = [["a", "b", "c"], ["dd", "ee", "ff"], ["ggg", "hhh", "iii"]]
|
13 | 34 | expected = "a dd ggg\nb ee hhh\nc ff iii"
|
|
0 commit comments