@@ -148,6 +148,13 @@ def fixture_df_int_first(csv_int_first):
148148 """
149149 return load_test_dataframe (csv_int_first )
150150
151+ @pytest .fixture (name = 'df_only_header' )
152+ def fixture_df_only_header (csv_only_header ):
153+ """df where only headers given and no data.
154+
155+ """
156+ return load_test_dataframe (csv_only_header )
157+
151158@pytest .fixture (name = "data" )
152159def load_test_navdata (df_simple ):
153160 """Creates a NavData instance from df_simple.
@@ -1716,3 +1723,40 @@ def test_in_rows_multi(data):
17161723 data_temp .in_rows (combo_rows )
17171724 for row in combo_rows :
17181725 assert row in str (excinfo .value )
1726+
1727+ def test_pandas_df (df_simple , df_only_header ):
1728+ """Test that the NavData class can be printed without errors
1729+
1730+ Parameters
1731+ ----------
1732+ df_simple : pd.DataFrame
1733+ Dataframe with which to construct NavData instance
1734+ df_only_header : pd.DataFrame
1735+ Dataframe with only column names and no data
1736+ """
1737+ navdata = NavData (pandas_df = df_simple )
1738+
1739+ # test simple DataFrame
1740+ pd .testing .assert_frame_equal (navdata .pandas_df ().sort_index (axis = 1 ),
1741+ df_simple .sort_index (axis = 1 ),
1742+ check_names = True , check_dtype = False )
1743+
1744+ # test DataFrame with a single row of data
1745+ df_super_simple = pd .DataFrame ([["first" ,1. ,3 ,"fourth" ]],
1746+ columns = ["A" ,"B" ,"C" ,"D" ])
1747+ navdata = NavData (pandas_df = df_super_simple )
1748+ pd .testing .assert_frame_equal (navdata .pandas_df ().sort_index (axis = 1 ),
1749+ df_super_simple .sort_index (axis = 1 ),
1750+ check_names = True , check_dtype = False )
1751+
1752+ # make sure print doesn't break if given only headers
1753+ navdata = NavData (pandas_df = df_only_header )
1754+ pd .testing .assert_frame_equal (navdata .pandas_df ().sort_index (axis = 1 ),
1755+ df_only_header .sort_index (axis = 1 ),
1756+ check_names = True )
1757+
1758+ # make sure it doesn't break with empty NavData
1759+ navdata = NavData ()
1760+ pd .testing .assert_frame_equal (navdata .pandas_df ().sort_index (axis = 1 ),
1761+ pd .DataFrame ().sort_index (axis = 1 ),
1762+ check_names = True )
0 commit comments