Coder Social home page Coder Social logo

-rust-command-line-tool-with-testing's Introduction

CSV Filter with Polars

A simple command-line tool built in Rust, utilizing the Polars library to filter rows from a CSV file based on a specified column's value exceeding a given threshold. This project showcases efficient data processing and error handling in Rust, leveraging the anyhow and clap crates for an improved developer and user experience.

Features

  • Filters a CSV file to only include rows where the specified column's value exceeds a given numeric threshold.
  • Utilizes clap for easy command-line argument parsing.
  • Implements error handling using anyhow for clearer error messages and propagation.
  • Includes basic unit tests to validate functionality.

Usage

To use this tool, you must specify three command-line arguments:

  • -f or --file: The path to the input CSV file.
  • -c or --column: The name of the column to filter on.
  • -t or --threshold: The numeric threshold for filtering.

Example command:

cargo run -- -f path/to/data.csv -c age -t 30

This command filters the data.csv file, returning rows where the value in the age column is greater than 30.

Building from Source

Ensure you have Rust installed on your machine. Then, clone this repository, navigate to the project directory, and build the project using Cargo:

cargo build --release

Running Unit Tests

This project includes unit tests for the filter_csv function to ensure its correct operation under various conditions, including successful filtering, no matches, and invalid column names. To run these tests, execute the following command in the project directory:

cargo test

The tests utilize temporary CSV files created at runtime to verify the filtering logic, ensuring robustness and correctness of the tool.

Dependencies

  • polars: For efficient data processing and filtering.
  • clap: For parsing command-line arguments.
  • anyhow: For simplified error handling.
  • tempfile: Used in tests for creating temporary CSV files.

Ensure all dependencies are added to your Cargo.toml file to build and run the project successfully.

-rust-command-line-tool-with-testing's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.