Skip to content
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

Merged
merged 15 commits into from
Aug 17, 2022
Merged

Add CSV data parsing #402

merged 15 commits into from
Aug 17, 2022

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Jul 27, 2022

🎉 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

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)

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.

@hidmic hidmic added the MBARI-LRAUV Sponsored by MBARI-LRAUV project: https:/osrf/lrauv label Jul 27, 2022
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Jul 27, 2022
@hidmic hidmic changed the title Add CSV parsing support Add CSV data parsing Jul 27, 2022
@hidmic hidmic mentioned this pull request Jul 27, 2022
22 tasks
@chapulina chapulina added the enhancement New feature or request label Jul 27, 2022
@chapulina
Copy link
Contributor

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

@hidmic
Copy link
Contributor Author

hidmic commented Jul 27, 2022

Instead of maintaining a custom CSV parser, maybe we can depend on / vendor an existing one?

@chapulina absolutely. There's no de-facto standard out there though, which is why I crafted a minimal implementation.

This is the first one that came up on my search: https:/d99kris/rapidcsv

That one is header-only and source distributed, so we would have to vendor it. Code's simple enough.

@hidmic hidmic marked this pull request as ready for review July 29, 2022 14:12
@hidmic hidmic requested a review from mjcarroll as a code owner July 29, 2022 14:12
@hidmic
Copy link
Contributor Author

hidmic commented Jul 29, 2022

@chapulina as per our discussion offline, I've updated this patch to rely on libcsv-dev for CSV parsing. I've also kept an iterator-based interface to it to avoid polluting the global namespace for gz-common. PTAL!

#include <gz/common/CSVStreams.hh>
#include <gz/common/Io.hh>

#include <gz/math/TimeVaryingVolumetricGrid.hh>
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

@hidmic hidmic Aug 1, 2022

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.

@chapulina chapulina added Breaking change Breaks API, ABI or behavior. Must target unstable version. needs upstream release Blocked by a release of an upstream library labels Jul 29, 2022
@traversaro
Copy link
Contributor

@chapulina as per our discussion offline, I've updated this patch to rely on libcsv-dev for CSV parsing. I've also kept an iterator-based interface to it to avoid polluting the global namespace for gz-common. PTAL!

Totally ok for me, but just to double check: are you aware that this would add a LGPL dependency that cannot be skipped to gz-common?

@chapulina
Copy link
Contributor

Totally ok for me, but just to double check: are you aware that this would add a LGPL dependency that cannot be skipped to gz-common?

Thanks for bringing it up, @traversaro , we hadn't noticed that. Still iterating.

@chapulina chapulina removed the Breaking change Breaks API, ABI or behavior. Must target unstable version. label Jul 30, 2022
@chapulina
Copy link
Contributor

Removed the Breaking change because the dependency on libcsv will be removed.

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]>
@hidmic
Copy link
Contributor Author

hidmic commented Aug 5, 2022

gazebosim/gz-math#456 is merged. This should pass CI in some hours.

@caguero mind to give it a pass?

@chapulina chapulina removed the 🌱 garden Ignition Garden label Aug 6, 2022
@chapulina
Copy link
Contributor

Removed the Garden label because we're past feature freeze ❄️ .

Since this PR is backwards-compatible, it could be targeted at Citadel and merged forward from there.

@caguero
Copy link
Contributor

caguero commented Aug 8, 2022

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)
Copy link
Contributor

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};
Copy link
Contributor

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.

{
template <typename T>
struct IO {
static T ReadFrom(std::istringstream &_istream)
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

@hidmic hidmic Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caguero I'll start by saying I didn't try this on Windows, BUT my understanding is that Windows will translate \r\n to \n when reading a text file (see here and here) so this dialect should work just fine there too.

Signed-off-by: Michel Hidalgo <[email protected]>
@codecov
Copy link

codecov bot commented Aug 9, 2022

Codecov Report

Merging #402 (be13770) into main (81c2ebd) will increase coverage by 0.10%.
The diff coverage is 86.82%.

@@            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     
Impacted Files Coverage Δ
io/include/gz/common/DataFrame.hh 76.27% <76.27%> (ø)
io/src/CSVStreams.cc 92.00% <92.00%> (ø)
io/include/gz/common/Io.hh 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@caguero caguero left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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]>
@hidmic
Copy link
Contributor Author

hidmic commented Aug 10, 2022

@caguero the Homebrew PR job is failing for unrelated reasons, see here.

BTW how do we go about validating the Bazel BUILD file?

@scpeters
Copy link
Member

@caguero the Homebrew PR job is failing for unrelated reasons, see here.

I believe that compiler warning has been fixed by #416

@mjcarroll
Copy link
Contributor

BTW how do we go about validating the Bazel BUILD file?

Don't worry about it for now, I have a batch of Bazel updates coming.

@hidmic hidmic changed the base branch from main to mbari/gz-common5 August 16, 2022 20:08
@hidmic hidmic changed the base branch from mbari/gz-common5 to main August 16, 2022 20:09
@hidmic
Copy link
Contributor Author

hidmic commented Aug 16, 2022

OK, I'll merge this into main, then backport to mbari/gz-common5. FYI @caguero.

@hidmic hidmic merged commit 4a982d7 into main Aug 17, 2022
@hidmic hidmic deleted the hidmic/csv-data branch August 17, 2022 13:50
hidmic added a commit that referenced this pull request Aug 17, 2022
Signed-off-by: Michel Hidalgo <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
@hidmic hidmic mentioned this pull request Sep 2, 2022
7 tasks
hidmic added a commit that referenced this pull request Oct 17, 2022
Signed-off-by: Michel Hidalgo <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
hidmic added a commit that referenced this pull request Oct 17, 2022
Signed-off-by: Michel Hidalgo <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request MBARI-LRAUV Sponsored by MBARI-LRAUV project: https:/osrf/lrauv needs upstream release Blocked by a release of an upstream library
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants