Class: Daru::IO::Importers::CSV
- Defined in:
- lib/daru/io/importers/csv.rb
Overview
CSV Importer Class, that extends read_csv
method to Daru::DataFrame
Constant Summary collapse
- CONVERTERS =
{ boolean: lambda { |f, _| case f.downcase.strip when 'true' then true when 'false' then false else f end } }.freeze
Class Method Summary collapse
-
.read(path) ⇒ Daru::IO::Importers::CSV
Reads data from a csv / csv.gz file.
Instance Method Summary collapse
-
#call(headers: nil, skiprows: 0, compression: :infer, clone: nil, index: nil, order: nil, name: nil, **options) ⇒ Daru::DataFrame
Imports a
Daru::DataFrame
from a CSV Importer instance. -
#initialize ⇒ CSV
constructor
Checks for required gem dependencies of CSV Importer.
-
#read(path) ⇒ Daru::IO::Importers::CSV
Reads data from a csv / csv.gz file.
Methods inherited from Base
Constructor Details
#initialize ⇒ CSV
Checks for required gem dependencies of CSV Importer
21 22 23 24 25 |
# File 'lib/daru/io/importers/csv.rb', line 21 def initialize require 'csv' require 'open-uri' require 'zlib' end |
Class Method Details
.read(path) ⇒ Daru::IO::Importers::CSV
Reads data from a csv / csv.gz file
41 42 43 44 45 |
# File 'lib/daru/io/importers/csv.rb', line 41 def read(path) @path = path @file_data = open(@path) self end |
Instance Method Details
#call(headers: nil, skiprows: 0, compression: :infer, clone: nil, index: nil, order: nil, name: nil, **options) ⇒ Daru::DataFrame
Imports a Daru::DataFrame
from a CSV Importer instance
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/daru/io/importers/csv.rb', line 115 def call(headers: nil, skiprows: 0, compression: :infer, clone: nil, index: nil, order: nil, name: nil, **) init_opts(headers: headers, skiprows: skiprows, compression: compression, clone: clone, index: index, order: order, name: name, **) process_compression # Preprocess headers for detecting and correcting repetition in # case the :headers option is not specified. hsh = if @headers hash_with_headers else hash_without_headers.tap { |hash| @daru_options[:order] = hash.keys } end Daru::DataFrame.new(hsh, @daru_options) end |
#read(path) ⇒ Daru::IO::Importers::CSV
Reads data from a csv / csv.gz file
41 42 43 44 45 |
# File 'lib/daru/io/importers/csv.rb', line 41 def read(path) @path = path @file_data = open(@path) self end |