Skip to content

Commit 5013acf

Browse files
committed
added concat tests, updated concat tutorial
1 parent cf7fe1b commit 5013acf

3 files changed

Lines changed: 76 additions & 5 deletions

File tree

notebooks/tutorials/navdata.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@
313313
"cell_type": "markdown",
314314
"metadata": {},
315315
"source": [
316-
"To add new columns, use the `NavData.add()` method with the `csv_path`, \n",
317-
"`pandas_df` and `numpy_array` flags depending on the input type."
316+
"To add new columns, use the `NavData.concat()` method which concatenates two `NavData` instances."
318317
]
319318
},
320319
{
@@ -341,7 +340,7 @@
341340
"metadata": {},
342341
"outputs": [],
343342
"source": [
344-
"nav_data_np.add(numpy_array=np_array)\n",
343+
"nav_data_np.concat(NavData(numpy_array=np_array),inplace=True)\n",
345344
"nav_data_np[:]"
346345
]
347346
},

tests/parsers/test_android.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,37 @@ def test_get_and_set_str(derived):
291291

292292
np.testing.assert_equal(derived[key, :], value)
293293

294+
def test_android_concat(derived, pd_df):
295+
"""Test concat on Android data.
296+
297+
Parameters
298+
----------
299+
derived : AndroidDerived2021
300+
Instance of AndroidDerived2021 for testing
301+
pd_df : pytest.fixture
302+
pd.DataFrame for testing measurements
303+
"""
304+
305+
# remove first timestamp to match
306+
pd_df = pd_df[pd_df['millisSinceGpsEpoch'] != pd_df.loc[0,'millisSinceGpsEpoch']]
307+
308+
# extract and combine gps and glonass data
309+
gps_data = derived.where("gnss_id","gps")
310+
glonass_data = derived.where("gnss_id","glonass")
311+
combined_navdata = gps_data.concat(glonass_data)
312+
313+
# combine using pandas
314+
gps_df = pd_df[pd_df["constellationType"]==1]
315+
glonass_df = pd_df[pd_df["constellationType"]==3]
316+
combined_df = pd.concat((gps_df,glonass_df))
317+
318+
# check a few rows to make sure they're equal
319+
np.testing.assert_array_equal(combined_navdata["raw_pr_m"],
320+
combined_df["rawPrM"])
321+
np.testing.assert_array_equal(combined_navdata["raw_pr_sigma_m"],
322+
combined_df["rawPrUncM"])
323+
np.testing.assert_array_equal(combined_navdata["intersignal_bias_m"],
324+
combined_df["isrbM"])
294325

295326
def test_imu_raw(android_raw_path):
296327
"""Test that AndroidRawImu initialization

tests/parsers/test_navdata.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,27 @@ def test_concat(df_simple):
13231323
# add new columns
13241324
navdata = navdata_1.concat(navdata_1)
13251325
assert navdata.shape == (4,12)
1326+
pandas_equiv = pd.concat((df_simple,df_simple),axis=0)
1327+
pandas_equiv.reset_index(drop=True, inplace=True)
1328+
pd.testing.assert_frame_equal(pandas_equiv.sort_index(axis=1),
1329+
navdata.pandas_df().sort_index(axis=1),
1330+
check_index_type=False,
1331+
check_dtype=False)
1332+
13261333
# add new rows
13271334
navdata = navdata_1.concat(navdata_1,axis=0)
13281335
assert navdata.shape == (8,6)
1336+
mapper = {"names":"names_0",
1337+
"floats":"floats_0",
1338+
"integers":"integers_0",
1339+
"strings":"strings_0"}
1340+
df_simple_2 = df_simple.rename(mapper,axis=1)
1341+
pandas_equiv = pd.concat((df_simple,df_simple_2),axis=1)
1342+
pandas_equiv.reset_index(drop=True, inplace=True)
1343+
pd.testing.assert_frame_equal(pandas_equiv.sort_index(axis=1),
1344+
navdata.pandas_df().sort_index(axis=1),
1345+
check_index_type=False,
1346+
check_dtype=False)
13291347

13301348
# test multiple rows with the same name
13311349
navdata_long = navdata_1.copy()
@@ -1337,10 +1355,33 @@ def test_concat(df_simple):
13371355
# add semi new columns
13381356
navdata = navdata_1.concat(navdata_2)
13391357
assert navdata.shape == (6,12)
1358+
assert np.all(np.isnan(navdata["floats"][-6:]))
1359+
assert np.all(navdata["names"][-6:] == np.array([np.nan]).astype(str)[0])
1360+
assert np.all(np.isnan(navdata["decimals"][:6]))
1361+
assert np.all(navdata["words"][:6] == np.array([np.nan]).astype(str)[0])
1362+
1363+
# add semi new columns in opposite order
1364+
navdata = navdata_2.concat(navdata_1)
1365+
assert navdata.shape == (6,12)
1366+
assert np.all(np.isnan(navdata["floats"][:6]))
1367+
assert np.all(navdata["names"][:6] == np.array([np.nan]).astype(str)[0])
1368+
assert np.all(np.isnan(navdata["decimals"][-6:]))
1369+
assert np.all(navdata["words"][-6:] == np.array([np.nan]).astype(str)[0])
13401370

13411371
# add as new rows
1342-
navdata_b = navdata_1.concat(navdata_2,axis=0)
1343-
assert navdata_b.shape == (8,6)
1372+
navdata = navdata_1.concat(navdata_2,axis=0)
1373+
assert navdata.shape == (8,6)
1374+
mapper = {"names":"words",
1375+
"floats":"decimals",
1376+
"integers":"integers_0",
1377+
"strings":"strings_0"}
1378+
df_simple_2 = df_simple.rename(mapper,axis=1)
1379+
pandas_equiv = pd.concat((df_simple,df_simple_2),axis=1)
1380+
pandas_equiv.reset_index(drop=True, inplace=True)
1381+
pd.testing.assert_frame_equal(pandas_equiv.sort_index(axis=1),
1382+
navdata.pandas_df().sort_index(axis=1),
1383+
check_index_type=False,
1384+
check_dtype=False)
13441385

13451386
def test_concat_fails(df_simple):
13461387
"""Test when concat should fail.

0 commit comments

Comments
 (0)