README.md

Daru-IO

A Ruby plugin-gem to daru gem, that extends support for many Import and
Export methods of Daru::DataFrame. This gem is intended to help Rubyists who are into Data Analysis or Web
Development, by serving as a general purpose conversion library that takes input in one format (say, JSON) and
converts it another format (say, Avro) while also making it incredibly easy to getting started on
analyzing data with daru.

While supporting various IO modules, daru-io also provides an easier way of adding more Importers / Exporters. It's strongly recommended to have a look at 'Creating your own IO modules' section, if you're interested in creating new Importers / Exporters.

HTML Importer

Note: This module works only for static tables on a HTML page, and won't work in cases where the table is being loaded into the HTML table by inline Javascript. This is how the Nokogiri gem works, and the HTML Importer also follows suit.

Mongo Importer

Note: The Mongo gem faces Argument Error : expected Proc Argument issue due to the bug in MRI Ruby 2.4.0 mentioned here. This seems to have been fixed in Ruby 2.4.1 onwards. Hence, please avoid using this Mongo Importer in Ruby version 2.4.0.

Exporters

The Daru::IO Exporters are intended to 'migrate' a Daru::DataFrame into a file, or database. All Exporters can be called in two ways - from Daru::IO or Daru::DataFrame.

#! Partially requires Format Exporterrequire'daru/io/exporters/format'#! Usage from Daru::IO
instance =Daru::IO::Exporters::Format.new(df, opts)
instance.to_s #=> Provides a file-writable string, which can be used in web applications for file download purposes
instance.to #=> Provides a Format instance
instance.write(path) #=> Writes to the given path#! Usage from Daru::DataFrame
string = df.to_format_string(opts) #=> Provides a file-writable string, which can be to write into a file later
instance = df.to_format(opts) #=> Provides a Format instance
df.write_format(path, opts) #=> Writes to the given path

Note: Please have a look at the respective Exporter Doc links below, for having a look at arguments and examples.

Creating your own IO modules

Daru-IO currently supports various Import / Export methods, as it can be seen from the above list. But the list is NEVER complete - there may always be specific use-case format(s) that you need very badly, but might not fit the needs of majority of the community. In such a case, don't worry - you can always tweak (aka monkey-patch) daru-io in your application. The architecture of daru-io provides a neater way of monkey-patching into Daru::DataFrame to support your unique use-case.

Adding new IO modules to Daru-IO

Say, your unique use-case is of YAML IO Modules. Here's how you can proceed with tweaking -

Behaviour of existing IO modules can also be reused according to your needs, similar to the above example. For example, if the CSV Importer has to be tweaked with a faster processing gem, simply follow an approach similar to this -