Skip to content

Commit d6097df

Browse files
committed
update __str__ for empty NavData and add more tests
1 parent c2535d1 commit d6097df

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

gnss_lib_py/parsers/navdata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ def __next__(self):
665665

666666
def __str__(self):
667667
str_out = str(self.pandas_df())
668+
str_out = str_out.replace("DataFrame","NavData")
669+
str_out = str_out.replace("Columns","Rows")
668670
return str_out
669671

670672
def __len__(self):

tests/parsers/test_navdata.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,15 @@ def test_is_str(df_simple):
16031603
with pytest.raises(KeyError):
16041604
navdata.is_str(0)
16051605

1606-
def test_str_navdata(df_simple):
1606+
def test_str_navdata(df_simple, df_only_header):
16071607
"""Test that the NavData class can be printed without errors
16081608
16091609
Parameters
16101610
----------
16111611
df_simple : pd.DataFrame
16121612
Dataframe with which to construct NavData instance
1613+
df_only_header : pd.DataFrame
1614+
Dataframe with only column names and no data
16131615
"""
16141616
navdata = NavData(pandas_df=df_simple)
16151617
navdata_str = str(navdata)
@@ -1618,6 +1620,18 @@ def test_str_navdata(df_simple):
16181620
df_str = str(df_simple)
16191621
assert navdata_str==df_str
16201622

1623+
# make sure print doesn't break if given only headers
1624+
navdata_str = str(NavData(pandas_df=df_only_header))
1625+
df_str = str(df_only_header).replace("DataFrame","NavData")
1626+
df_str = df_str.replace("Columns","Rows")
1627+
assert navdata_str==df_str
1628+
1629+
# make sure it doesn't break with empty NavData
1630+
navdata_str = str(NavData())
1631+
df_str = str(pd.DataFrame()).replace("DataFrame","NavData")
1632+
df_str = df_str.replace("Columns","Rows")
1633+
assert navdata_str==df_str
1634+
16211635
def test_in_rows_single(data):
16221636
"""Test the in_rows function.
16231637

0 commit comments

Comments
 (0)