The changes are to improve robustness and to reduce the risk of data loss
-
implementing auto-detection of extra columns (thanks to James Fenley)
-
improved handling of unbalanced quote_char in input (issue 288) thanks to Simon Rentzke), and (issue 283) thanks to James Fenley, Randall B, Matthew Kennedy) -> SmarterCSV will now raise
SmarterCSV::MalformedCSV
for unbalanced quote_char. -
bugfix / improved handling of extra columns in input data (issue 284) (thanks to James Fenley)
-
previous behavior: when a CSV row had more columns than listed in the header, the additional columns were ignored
-
new behavior:
- new default behavior is to auto-generate additional headers, e.g. :column_7, :column_8, etc
- you can set option
:strict
to true in order to get aSmarterCSV::MalformedCSV
exception instead
-
-
setting
user_provided_headers
now impliesheaders_in_file: false
(issue 282)The option
user_provided_headers
can be used to specify headers when there are none in the input, OR to completely override headers that are in the input (file).SmarterCSV is now using a safer default behavior.
-
previous behavior: Setting
user_provided_headers
did not change the defaultheaders_in_file: true
If the input had no headers, this would cause the first line to be erroneously treated as a header, and the user could lose the first row of data. -
new behavior: Setting
user_provided_headers
setsheaders_in_file: false
a) Improved behavior if there was no header in the input data. b) If there was a header in the input data, anduser_provided_headers
is used to override the headers in the file, then please explicitly specifyheaders_in_file: true
, otherwise you will get an extra hash which includes the header data.
IF you set
user_provided_headers
and the file has a header, then provideheaders_in_file: true
to avoid getting that extra record. -
-
improved documentation for handling of numeric columns with leading zeroes, e.g. ZIP codes. (issue #151 thanks to David Moles).
convert_values_to_numeric: { except: [:zip] }
will return a string for that column instead (since version 1.10.x)
- Improved column separator detection by ignoring quoted sections #276 (thanks to Nicolas Castellanos)
-
Added Thread-Safety: added SmarterCSV::Reader to process CSV files in a thread-safe manner (issue #277)
-
SmarterCSV::Writer changed default row separator to the system's row separator (
\n
on Linux,\r\n
on Windows) -
added a doc tree
-
POTENTIAL ISSUE:
Version 1.12.x has a change of the underlying implementation of
SmarterCSV.process(file_or_input, options, &block)
. Underneath it now uses this interface:reader = SmarterCSV::Reader.new(file_or_input, options) # either simple one-liner: data = reader.process # or block format: data = reader.process do # do something here end
It still supports calling
SmarterCSV.process
for backwards-compatibility, but it no longer provides access to the internal state, e.g. raw_headers.SmarterCSV.raw_headers
->reader.raw_headers
SmarterCSV.headers
->reader.headers
If you need these features, please update your code to create an instance of
SmarterCSV::Reader
as shown above.
- fixing missing errors definition
- improved behavior of Writer class
- added SmarterCSV.generate shortcut for CSV writing
- added SmarterCSV::Writer to output CSV files (issue #44)
- fixed issue when frozen options are handed in (thanks to Daniel Pepper)
- cleaned-up rspec tests (thanks to Daniel Pepper)
- fixed link in README (issue #251)
- improve error message for missing keys
- fix incorrect warning about UTF-8 (issue #268, thanks hirowatari)
-
BREAKING CHANGES:
Changed behavior:
-
when
user_provided_headers
are provided:- if they are not unique, an exception will now be raised
- they are taken "as is", no header transformations can be applied
- when they are given as strings or as symbols, it is assumed that this is the desired format
- the value of the
strings_as_keys
options will be ignored
-
option
duplicate_header_suffix
now defaults to''
instead ofnil
.- this allows automatic disambiguation when processing of CSV files with duplicate headers, by appending a number
- explicitly set this option to
nil
to get the behavior from previous versions.
-
-
performance and memory improvements
-
code refactor
- raise SmarterCSV::IncorrectOption when
user_provided_headers
are empty - code refactor / no functional changes
- added test cases
- fixed bug with '\' at end of line (issue #252, thanks to averycrespi-moz)
- fixed require statements (issue #249, thanks to PikachuEXE, courtsimas)
- yanked
- no functional changes
- refactored directory structure
- re-added JRuby and TruffleRuby to CI tests
- no C-accelleration for JRuby
- refactored options parsing
- code coverage / rubocop
-
fixed issue #139
-
Error
SmarterCSV::MissingHeaders
was renamed toSmarterCSV::MissingKeys
-
CHANGED BEHAVIOR: When
key_mapping
option is used. (issue #139) Previous versions just printed an error message when a CSV header was missing during key mapping. Versions >= 1.9 will throwSmarterCSV::MissingHeaders
listing all headers that were missing during mapping. -
Notable details for
key_mapping
andrequired_headers
:key_mapping
is applied to the headers early on duringSmarterCSV.process
, and raises an error if a header in the input CSV file is missing, and we can not map that header to its desired name.
Mapping errors can be surpressed by using:
-
silence_missing_keys
set totrue
, which silence all such errors, making all headers for mapping optional. -
silence_missing_keys
given an Array with the specific header keys that are optional The use case is that some header fields are optional, but we still want them renamed if they are present. -
required_headers
checks which headers are present afterkey_mapping
was applied.
- fix parsing of escaped quote characters (thanks to JP Camara)
- fix gem loading issue (issue #232, #234)
- bugfix: windows one-column files were raising NoColSepDetected (issue #229)
- bugfix: do not raise
NoColSepDetected
for CSV files with only one column in most cases (issue #222) If the first lines contain non-ASCII characters, and no col_sep is detected, it will still raiseNoColSepDetected
- added validation against invalid values for :col_sep, :row_sep, :quote_char (issue #216)
- deprecating
required_headers
and replace withrequired_keys
(issue #140) - fixed issue with require statement
-
NEW DEFAULTS:
col_sep: :auto
,row_sep: :auto
. Fully automatic detection by default.MAKE SURE to rescue
NoColSepDetected
if your CSV files can have unexpected formats, e.g. from users uploading them to a service, and handle those cases. -
ignore Byte Order Marker (BOM) in first line in file (issues #27, #219)
- improved guessing of the column separator, thanks to Alessandro Fazzi
- new option :silence_missing_keys; if set to true, it ignores missing keys in
key_mapping
- new option :with_line_numbers; if set to true, it adds :csv_line_number to each data hash (issue #130)
- bugfix for issue #195 #197 #200 which only appeared when called from Rails (thanks to Viacheslav Markin, Nicolas Rodriguez)
- added native code to accellerate line parsing by >10x over 1.6.0
- added option
acceleration
, defaulting totrue
, to enable native code. Disable this option to use the ruby code for line parsing. - increased test coverage to 100%
- rubocop changes
- fixed compiling
- rubocop changes
- published pre-release
- added native code to accellerate line parsing by >10x over 1.6.0
- added option
acceleration
, defaulting totrue
, to enable native code. Disable this option to use the ruby code for line parsing. - increased test coverage to 100%
- unused keys in
key_mapping
now generate a warning, no longer raise an exception This is preferable whenkey_mapping
is done defensively for variabilities in the CSV files.
- completely rewrote line parser
- added methods
SmarterCSV.raw_headers
andSmarterCSV.headers
to allow easy examination of how the headers are processed.
- added missing keys to the SmarterCSV::KeyMappingError exception message #189 (thanks to John Dell)
- added raising of
KeyMappingError
ifkey_mapping
refers to a non-existent key - added option
duplicate_header_suffix
(thanks to Skye Shaw) When given a non-nil string, it uses the suffix to append numbering 2..n to duplicate headers. If your code will need to process arbitrary CSV files, please setduplicate_header_suffix
.
-
fixed bug with trailing col_sep characters, introduced in 1.4.0
-
Fix deprecation warning in Ruby 3.0.3 / $INPUT_RECORD_SEPARATOR (thanks to Joel Fouse )
-
changed default for
comment_regexp
to benil
for a safer default behavior (thanks to David Lazar) Note This no longer assumes that lines starting with#
are comments. If you want to treat lines starting with '#' as comments, usecomment_regexp: /\A#/
- fixed issue with simplecov
- minor fix: also support
col_sep: :auto
- added simplecov
- dropped GPL license, smarter_csv is now only using the MIT License
- added experimental option
col_sep: 'auto
to auto-detect the column separator (issue #183) The default behavior is still to assume,
is the column separator. - fixed buggy behavior when using
remove_empty_values: false
(issue #168) - fixed Ruby 3.0 deprecation
-
fix bug for key_mappings (issue #181)
The values of thekey_mappings
hash will now be used "as is", and no longer forced to be symbolsUsers with existing code with
--key_mappings
need to change their code to- either use symbols in the
key_mapping
hash - or change the expected keys from symbols to strings
- either use symbols in the
- fix bug for key_mappings (issue #181)
The values of the
key_mappings
hash will now be used "as is", and no longer forced to be symbols
- fix deprecation warnings on Ruby 2.7 (thank to Diego Salido)
- fixing error caused by calling f.close when we do not hand in a file
- fixing issue #136 with comments in CSV files
- fixing error class hierarchy
- using Rails blank? if it's available
- fixed regression / test
- fuxed quote_char interpolation for headers, but not data (thanks to Colin Petruno)
- bugfix (thanks to Joshua Smith for reporting)
- add default validation that a header can only appear once
- add option
required_headers
- fix issue with invalid byte sequences in header (issue #103, thanks to Dave Myron)
- fix issue with invalid byte sequences in multi-line data (thanks to Ivan Ushakov)
- analyze only 500 characters by default when
:row_sep => :auto
is used. added optionrow_sep_auto_chars
to change the default if necessary. (thanks to Matthieu Paret)
- fixing UTF-8 related bug which was introduced in 1.1.2 (thanks to Tirdad C.)
- added warning when options indicate UTF-8 processing, but input filehandle is not opened with r:UTF-8 option
- added option
invalid_byte_sequence
(thanks to polycarpou) - added comments on handling of UTF-8 encoding when opening from File vs. OpenURI (thanks to KevinColemanInc)
- added option to
skip_lines
(thanks to wal) - added option to
force_utf8
encoding (thanks to jordangraft) - bugfix if no headers in input data (thanks to esBeee)
- ensure input file is closed (thanks to waldyr)
- improved verbose output (thankd to benmaher)
- improved documentation
- added feature :value_converters, which allows parsing of dates, money, and other things (thanks to Raphaël Bleuse, Lucas Camargo de Almeida, Alejandro)
- added error if :headers_in_file is set to false, and no :user_provided_headers are given (thanks to innhyu)
- added support to convert dashes to underscore characters in headers (thanks to César Camacho)
- fixing automatic detection of \r\n line-endings (thanks to feens)
- added option :keep_original_headers to keep CSV-headers as-is (thanks to Benjamin Thouret)
- added support for multi-line fields / csv fields containing CR (thanks to Chris Hilton) (issue #31)
- added option to set :row_sep to :auto , for automatic detection of the row-separator (issue #22)
- :convert_values_to_numeric option can now be qualified with :except or :only (thanks to Hugo Lepetit)
- removed deprecated
process_csv
method
- new option:
- :remove_unmapped_keys to completely ignore columns which were not mapped with :key_mapping (thanks to Dave Sanders)
- added GPL-2 and MIT license to GEM spec file; if you need another license contact me
- added RSpec tests
- bugfix : fixed issue #18 - fixing issue with last chunk not being properly returned (thanks to Jordan Running)
- added RSpec tests
- bugfix : fixed issue #14 - passing options along to CSV.parse (thanks to Marcos Zimmermann)
- bugfix : fixed issue #13 with negative integers and floats not being correctly converted (thanks to Graham Wetzler)
- bugfix : fixed issue with nil values in inputs with quote-char (thanks to Félix Bellanger)
- new options:
- :force_simple_split : to force simiple splitting on :col_sep character for non-standard CSV-files. e.g. without properly escaped :quote_char
- :verbose : print out line number while processing (to track down problems in input files)
- allowing process to work with objects with a 'readline' method (thanks to taq)
- added options:
- :file_encoding : defaults to utf8 (thanks to MrTin, Paxa)
- bugfix : quoted fields are now correctly parsed
- bugfix : for :headers_in_file option
- renamed the following options:
- :strip_whitepace_from_values => :strip_whitespace - removes leading/trailing whitespace from headers and values
- added the following options:
- :strip_whitepace_from_values - removes leading/trailing whitespace from values
- added more options for dealing with headers:
- :user_provided_headers ,user provided Array with header strings or symbols, to precisely define what the headers should be, overriding any in-file headers (default: nil)
- :headers_in_file , if the file contains headers as the first line (default: true)
-
added the following options:
- :downcase_header
- :strings_as_keys
- :remove_zero_values
- :remove_values_matching
- :remove_empty_hashes
- :convert_values_to_numeric
-
renamed the following options:
- :remove_empty_fields => :remove_empty_values
- renamed
SmarterCSV.process_csv
toSmarterCSV.process
.