Skip to content

Commit 6ef0e0b

Browse files
committed
swap rows and columns when printing for consitency
1 parent 2f28d3f commit 6ef0e0b

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

gnss_lib_py/parsers/navdata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
__date__ = "03 Nov 2021"
77

88
import os
9+
import re
910
import copy
1011

1112
import numpy as np
@@ -664,6 +665,10 @@ def __str__(self):
664665
str_out = str(self.pandas_df())
665666
str_out = str_out.replace("DataFrame","NavData")
666667
str_out = str_out.replace("Columns","Rows")
668+
# swap rows and columns when printing for NavData consistency
669+
str_out = re.sub(r"(.*)\[(\d+)\srows\sx\s(\d+)\scolumns\](.*)",
670+
r'\g<1>[\g<3> rows x \g<2> columns]\g<4>',
671+
str_out)
667672
return str_out
668673

669674
def __len__(self):

tests/parsers/test_navdata.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,14 @@ def test_str_navdata(df_simple, df_only_header):
16671667
df_str = df_str.replace("Columns","Rows")
16681668
assert navdata_str==df_str
16691669

1670+
# test DataFrame with a single row of data
1671+
df_long = pd.DataFrame(np.zeros((200,4)),
1672+
columns=["A","B","C","D"])
1673+
navdata = NavData(pandas_df=df_long)
1674+
assert str(navdata) == str(df_long).replace("[200 rows x 4 columns]",
1675+
"[4 rows x 200 columns]")
1676+
1677+
16701678
def test_in_rows_single(data):
16711679
"""Test the in_rows function.
16721680

0 commit comments

Comments
 (0)