Skip to content

Commit a63a0c3

Browse files
Merge pull request #152 from Stanford-NavLab/ashwin/copy_no_cols_bug_fix
Fixed issue with num_cols initialization and setting after `NavData.copy()`
2 parents ead1f77 + 12f3abd commit a63a0c3

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

gnss_lib_py/navdata/navdata.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class NavData():
5050
str_map : Dict
5151
Map of the form {pandas column name : {array value : string}}.
5252
Map is of the form {pandas column name : {}} for non string rows.
53-
num_cols : int
54-
Number of columns in array containing data, set to 0 by default
55-
for empty NavData
5653
curr_cols : int
5754
Current number of column for iterator, set to 0 by default
5855
@@ -70,7 +67,6 @@ def __init__(self, csv_path=None, pandas_df=None, numpy_array=None,
7067
# Attributes for looping over all columns
7168

7269
self.curr_col = 0
73-
self.num_cols = 0
7470

7571
if csv_path is not None:
7672
self.from_csv_path(csv_path, **kwargs)
@@ -81,6 +77,7 @@ def __init__(self, csv_path=None, pandas_df=None, numpy_array=None,
8177
else:
8278
self._build_navdata()
8379

80+
8481
if len(self) > 0:
8582
self.rename(self._row_map(), inplace=True)
8683
self.postprocess()
@@ -694,6 +691,18 @@ def shape(self):
694691
shp = np.shape(self.array)
695692
return shp
696693

694+
@property
695+
def num_cols(self):
696+
"""Return the number of columns in the NavData instance.
697+
698+
Returns
699+
-------
700+
num_cols : int
701+
Number of columns in the NavData instance.
702+
"""
703+
num_cols = self.shape[1]
704+
return num_cols
705+
697706
@property
698707
def rows(self):
699708
"""Return all row names in instance as a list
@@ -879,7 +888,6 @@ def __iter__(self):
879888
Instantiation of NavData class with iteration initialized
880889
"""
881890
self.curr_col = 0
882-
self.num_cols = np.shape(self.array)[1]
883891
return self
884892

885893
def __next__(self):
@@ -890,7 +898,7 @@ def __next__(self):
890898
x_curr : gnss_lib_py.navdata.navdata.NavData
891899
Current column (based on iteration count)
892900
"""
893-
if self.curr_col >= self.num_cols:
901+
if self.curr_col >= len(self):
894902
raise StopIteration
895903
x_curr = self.copy(rows=None, cols=self.curr_col)
896904
self.curr_col += 1

notebooks/tutorials/navdata/navdata.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@
360360
"len(nav_data_csv)"
361361
]
362362
},
363+
{
364+
"cell_type": "code",
365+
"execution_count": null,
366+
"metadata": {},
367+
"outputs": [],
368+
"source": [
369+
"nav_data_csv.num_cols"
370+
]
371+
},
363372
{
364373
"cell_type": "markdown",
365374
"metadata": {},

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gnss-lib-py"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
description = "Modular Python tool for parsing, analyzing, and visualizing Global Navigation Satellite Systems (GNSS) data and state estimates"
55
authors = ["Derek Knowles <dcknowles@stanford.edu>",
66
"Ashwin Kanhere <akanhere@stanford.edu>",

tests/navdata/test_navdata.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,30 @@ def test_init_np(numpy_array):
175175
with pytest.raises(TypeError):
176176
data = NavData(numpy_array=pd.DataFrame([0]))
177177

178+
179+
def test_len_rows(data):
180+
"""Test that `len()` and `rows` return correct output.
181+
182+
Parameters
183+
----------
184+
data : gnss_lib_py.navdata.navdata.NavData
185+
Simple version of NavData to use for test.
186+
"""
187+
assert len(data) == 6
188+
assert data.rows == ['names', 'integers', 'floats', 'strings']
189+
190+
191+
def test_num_cols(data):
192+
"""Test that `num_cols` returns correct output.
193+
194+
Parameters
195+
----------
196+
data : gnss_lib_py.navdata.navdata.NavData
197+
Simple version of NavData to use for test."""
198+
assert data.num_cols == 6
199+
200+
201+
178202
@pytest.mark.parametrize('pandas_df',
179203
[
180204
lazy_fixture("df_simple"),

tests/utils/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def pytest_collection_modifyitems(items):
3838

3939
module_mapping = {item: item.module.__name__ for item in items}
4040
download_tests = [
41-
"test_ephemeris_downloader"
41+
"test_ephemeris_downloader",
42+
"test_rinex_nav",
43+
"test_rinex_obs"
4244
]
4345
sorted_items = [item for item in items if module_mapping[item] not in download_tests] \
4446
+ [item for item in items if module_mapping[item] in download_tests]

0 commit comments

Comments
 (0)