-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CSV data parsing #402
Add CSV data parsing #402
Conversation
Instead of maintaining a custom CSV parser, maybe we can depend on / vendor an existing one? This is the first one that came up on my search: https:/d99kris/rapidcsv |
@chapulina absolutely. There's no de-facto standard out there though, which is why I crafted a minimal implementation.
That one is header-only and source distributed, so we would have to vendor it. Code's simple enough. |
@chapulina as per our discussion offline, I've updated this patch to rely on |
include/gz/common/DataFrame.hh
Outdated
#include <gz/common/CSVStreams.hh> | ||
#include <gz/common/Io.hh> | ||
|
||
#include <gz/math/TimeVaryingVolumetricGrid.hh> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently there are gz-common components that depend on gz-math, but the gz-common core library does not. We should consider moving the code in this PR to its own csv
component or adding a math dependency to gz-common core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could also be added as a component of gz-utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider moving the code in this PR to its own csv component
Moved the whole IO concept to its own component in a925186. Haven't tested the Bazel bit yet but hopefully I didn't messed it up.
Totally ok for me, but just to double check: are you aware that this would add a LGPL dependency that cannot be skipped to |
Thanks for bringing it up, @traversaro , we hadn't noticed that. Still iterating. |
Removed the |
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
This reverts commit 380845f. Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
gazebosim/gz-math#456 is merged. This should pass CI in some hours. @caguero mind to give it a pass? |
Removed the Since this PR is backwards-compatible, it could be targeted at Citadel and merged forward from there. |
Reminder: We'll need to update gz-common5-release with the new component. @j-rivero . |
|
||
const CSVDialect CSVDialect::Unix = {',', '\n', '"'}; | ||
|
||
bool operator==(const CSVDialect &_lhs, const CSVDialect &_rhs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use function delimiter /////////////////////////////////////////////////
. See other .cc
files for examples.
} | ||
} | ||
|
||
public: std::istream *stream{nullptr}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add doxygen to these data members.
io/include/gz/common/Io.hh
Outdated
{ | ||
template <typename T> | ||
struct IO { | ||
static T ReadFrom(std::istringstream &_istream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document these functions?
char quote; | ||
|
||
/// CSV dialect as expected by Unix tools. | ||
static const CSVDialect Unix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this parser work with Windows for example? If not I think we should mention it somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Michel Hidalgo <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #402 +/- ##
==========================================
+ Coverage 80.38% 80.48% +0.10%
==========================================
Files 85 88 +3
Lines 9944 10111 +167
==========================================
+ Hits 7993 8138 +145
- Misses 1951 1973 +22
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor documentation comments but looks good to me!
class DataFrame | ||
{ | ||
/// \brief Check if column key is present. | ||
public: bool Has(const K &_key) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document _key
and return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9a3c84d.
} | ||
|
||
/// \brief Fetch mutable reference to column | ||
public: V &operator[](const K &_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document _key
and return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9a3c84d.
} | ||
|
||
/// \brief Fetch immutable reference to column | ||
public: const V &operator[](const K &_key) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document _key
and return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9a3c84d.
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]>
Don't worry about it for now, I have a batch of Bazel updates coming. |
OK, I'll merge this into |
Signed-off-by: Michel Hidalgo <[email protected]> Co-authored-by: Carlos Agüero <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]> Co-authored-by: Carlos Agüero <[email protected]>
Signed-off-by: Michel Hidalgo <[email protected]> Co-authored-by: Carlos Agüero <[email protected]>
🎉 New feature
Summary
This patch adds enough functionality to read a data frame from a CSV stream of data. This will come in handy for plugins that need additional data, external to the simulation.
Needs gazebosim/gz-math#456.
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.