File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 11ITables ChangeLog
22=================
33
4+ 1.1.3 (2022-08-11)
5+ ------------------
6+
7+ ** Fixed**
8+ - Tables with duplicate column names are now supported, thanks to Antonio Commisso's fix ([ #89 ] ( https://github.com/mwouts/jupytext/issues/89 ) )
9+
10+
4111.1.2 (2022-06-30)
512------------------
613
Original file line number Diff line number Diff line change @@ -104,19 +104,21 @@ def init_notebook_mode(
104104def _formatted_values (df ):
105105 """Return the table content as a list of lists for DataTables"""
106106 formatted_df = df .copy ()
107- for col in formatted_df :
108- x = formatted_df [col ]
107+ # We iterate over columns using an index rather than the column name
108+ # to avoid an issue in case of duplicate column names #89
109+ for j , col in enumerate (formatted_df ):
110+ x = formatted_df .iloc [:, j ]
109111 if x .dtype .kind in ["b" , "i" , "s" ]:
110112 continue
111113
112114 if x .dtype .kind == "O" :
113- formatted_df [ col ] = formatted_df [ col ].astype (str )
115+ formatted_df . iloc [:, j ] = formatted_df . iloc [:, j ].astype (str )
114116 continue
115117
116- formatted_df [ col ] = np .array (fmt .format_array (x .values , None ))
118+ formatted_df . iloc [:, j ] = np .array (fmt .format_array (x .values , None ))
117119 if x .dtype .kind == "f" :
118120 try :
119- formatted_df [ col ] = formatted_df [ col ].astype (float )
121+ formatted_df . iloc [:, j ] = formatted_df . iloc [:, j ].astype (float )
120122 except ValueError :
121123 pass
122124
Original file line number Diff line number Diff line change 11"""ITables' version number"""
22
3- __version__ = "1.1.2 "
3+ __version__ = "1.1.3 "
Original file line number Diff line number Diff line change 1+ import pandas as pd
12import pytest
23
34from itables import show
@@ -39,3 +40,9 @@ def test_show_test_dfs(df_name, df):
3940@pytest .mark .parametrize ("series_name,series" , get_dict_of_test_series ().items ())
4041def test_show_test_series (series_name , series ):
4142 show (series )
43+
44+
45+ def test_show_df_with_duplicate_column_names ():
46+ df = pd .DataFrame ({"a" : [0 ], "b" : [0.0 ], "c" : ["str" ]})
47+ df .columns = ["duplicated_name" ] * 3
48+ show (df )
You can’t perform that action at this time.
0 commit comments