Skip to content

Commit

Permalink
Adds an API to retrieve keys. (#446)
Browse files Browse the repository at this point in the history
This is useful for when we perform visualization.

Signed-off-by: Arjo Chakravarty <[email protected]>
Co-authored-by: Michael Carroll <[email protected]>
  • Loading branch information
2 people authored and hidmic committed Oct 17, 2022
1 parent c29c69e commit efcf016
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions io/include/gz/common/DataFrame.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ namespace gz
return this->storage.at(_key);
}

/// \brief Retrieve all keys
/// \return A vector with keys
public: const std::vector<K> Keys() const
{
std::vector<K> keyList;
for (auto &[k, _]: this->storage)
{
keyList.push_back(k);
}
return keyList;
}

/// \brief Data frame storage
private: std::unordered_map<K, V> storage;
};
Expand Down
6 changes: 5 additions & 1 deletion io/src/DataFrame_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ TEST(DataFrameTests, SimpleCSV)
temperatureSession.value(), position);
ASSERT_TRUE(temperature.has_value());
EXPECT_DOUBLE_EQ(25.1, temperature.value());
auto keys = df.Keys();
ASSERT_EQ(keys.size(), 1);
ASSERT_EQ(keys[0], "temperature");
}

/////////////////////////////////////////////////
Expand All @@ -87,7 +90,8 @@ TEST(DataFrameTests, ComplexCSV)
EXPECT_TRUE(df.Has("temperature"));
EXPECT_TRUE(df.Has("humidity"));
ASSERT_TRUE(df.Has("pressure"));

auto keys = df.Keys();
ASSERT_EQ(keys.size(), 3);
const DataT &pressureData = df["pressure"];
auto pressureSession = pressureData.CreateSession();
const math::Vector3d position{36.80079505, -121.789472517, 0.8};
Expand Down

0 comments on commit efcf016

Please sign in to comment.