Giter Site home page Giter Site logo

rbotafogo / jcsv Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 0.0 2.09 MB

CSV read and write for JRuby based on uniVocity

License: Other

Ruby 100.00%
csv csv-converter csv-document csv-files csv-import csv-parser csv-parsing csv-reader csv-reading jruby mdarray multidimensional ruby rubydatascience

jcsv's People

Contributors

rbotafogo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jcsv's Issues

Exception inside block

Hi,

It seems to be impossible to catch an exception inside the block that is passed to reader#read. My code looks like this:

reader = Jcsv.reader(path,
                format: :map)
    reader.filters = { :agno => Jcsv.int, :rbd => Jcsv.int }
    reader.read do |ln, rn, row, headers|
      begin
        writer << row
      rescue
        # skip row
      end
    end

A row in my CSV contains an invalid value for the rbd column, causing jCSV to throw an exception

Jcsv::FilterError: '9089ÃSICA JOSÉ TORIBIO MEDINA' could not be parsed as an Integer in {lineNo=1576684, rowNo=1576684, columnNo=2, rowSource=[2011, 9089ÃSICA JOSÉ TORIBIO MEDINA, 13, 13120, ÑUÑOA, 1, 0, 110, 1, A, 12037904, 1, 20040909, 0, 13120, ÑUÑOA,  ,  , 20110215, 5,7, 91, P, P]}
                     execute at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/numeric_filters.rb:42
  block in executeProcessors at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:122
             each_with_index at uri:classloader:/jruby/java/java_ext/java.lang.rb:19
           executeProcessors at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:96
                filter_input at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:220
                        read at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/supercsv_interface.rb:209
                  read_chunk at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/reader.rb:352
                  read_chunk at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/map_reader.rb:184
            parse_with_block at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/reader.rb:101
                        read at /home/hermes/.rvm/gems/jruby-9.0.5.0/gems/mdarray-jCSV-0.6.2-java/lib/map_reader.rb:92

Is there anyway to skip a row that fails to validate the filters?

PS: Thanks for this gem! It's making my life a lot easier :)

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.