summaryrefslogtreecommitdiff
path: root/lib/csv.rb
AgeCommit message (Collapse)Author
2019-10-12Import CSV 3.1.2 (#2547)Sutou Kouhei
Notes: Merged-By: kou <kou@clear-code.com>
2019-09-25Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans
Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function. Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2019-08-30Fix keyword argument separation issues in libJeremy Evans
Mostly requires adding ** in either calls or method definitions. Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-13Fix a typo [ci skip]Kazuhiro NISHIYAMA
2019-07-25Fix a typo in inspectKazuhiro NISHIYAMA
2019-07-14[ruby/csv] add options doc :quote_empty (#89)kawa_tech
https://github.com/ruby/csv/commit/5ca8d79f60
2019-07-14[ruby/csv] Add options doc: :write_converters, :write_nil_value, ↵Masafumi Koba
:write_empty_value (#87) https://github.com/ruby/csv/commit/5923ee08b7
2019-07-14[ruby/csv] add document of strip (#88)hayashiyoshino
* add document of strip * modify typo https://github.com/ruby/csv/commit/de0257dc31
2019-07-14[ruby/csv] Don't raise on eof?Kouhei Sutou
GitHub: fix #86 Reported by krororo. Thanks!!! https://github.com/ruby/csv/commit/5a8d9d9297
2019-04-14Import CSV 3.0.8kou
This includes performance improvements and backward incompatibility fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-25Upgrade CSV to 3.0.4kou
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-23Import CSV 3.0.2kou
This includes performance improvement especially writing. Writing is about 2 times faster. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-05Merge csv-3.0.0 from ruby/csv repository.hsbt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-09Merge csv-1.0.2 from upstream.hsbt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-18Improve CSV performancewatson1978
If it will not use special variables (like $1, $&, $`...), it can improve the performance by using Regexp#match? or String#match? instead of Regexp#=~ or String#=~. This patch is same idea as https://github.com/ruby/ruby/pull/1836 [Fix GH-1842] ## Environment * OS : Ubuntu 17.10 * Compiler : gcc version 7.2.0 * CPU : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz * Memory : 16 GB ## TL;DR Methods | Before | After | Speed up ----------- | ------ | ------ | -------- CSV.foreach | 44.825 | 48.201 | 7.5% CSV#shift | 45.200 | 49.584 | 9.7% CSV.read | 42.968 | 46.853 | 9.0% CSV.table | 10.933 | 11.277 | 3.1% ## Before ``` Calculating ------------------------------------- CSV.foreach 44.825 (± 0.0%) i/s - 228.000 in 5.086576s CSV#shift 45.200 (± 0.0%) i/s - 228.000 in 5.044297s CSV.read 42.968 (± 0.0%) i/s - 216.000 in 5.027504s CSV.table 10.933 (± 0.0%) i/s - 55.000 in 5.031098s ``` ## After ``` Calculating ------------------------------------- CSV.foreach 48.201 (± 0.0%) i/s - 244.000 in 5.062256s CSV#shift 49.584 (± 0.0%) i/s - 248.000 in 5.001652s CSV.read 46.853 (± 0.0%) i/s - 236.000 in 5.037044s CSV.table 11.277 (± 0.0%) i/s - 57.000 in 5.054694s ``` ## Benchmark code ```ruby require 'csv' require 'benchmark/ips' CSV.open("/tmp/file.csv", "w") do |csv| csv << ["player", "gameA", "gameB"] 1000.times do csv << ['"Alice"', "84.0", "79.5"] csv << ['"Bob"', "20.0", "56.5"] end end Benchmark.ips do |x| x.report "CSV.foreach" do CSV.foreach("/tmp/file.csv") do |row| end end x.report "CSV#shift" do CSV.open("/tmp/file.csv") do |csv| while line = csv.shift end end end x.report "CSV.read" do CSV.read("/tmp/file.csv") end x.report "CSV.table" do CSV.table("/tmp/file.csv") end end ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12Merge csv-0.1.0 from upstream.hsbt
* csv.gemspec: Update release version. * lib/csv.rb: Remove superfluous private clause. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-29Partly reverted r59642. Because IO#close is idempotent since Ruby 2.3.hsbt
Reported by Eric Wong. Thank you. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-28lib/csv.rb: refactor and optimize. This changeglass
includes the patch from marshall-lee. close #1168 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-25csv.rb: optimize CSV::Table#to_a and #to_csvglass
* lib/csv.rb (CSV::Table#to_a, #to_csv): use Array#push instead of Array#concat for performance improvement. This performance improvement is proposed by zdennis <zach.dennis@gmail.com>. The patch is from Mau Magnaguagno <maumagnaguagno@gmail.com>. close #946 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22Fixed regression to convert blank value at r45497.hsbt
[Bug #11126][ruby-core:69088] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22Gracefully handle CSV IO when file descriptor closed.hsbt
[Bug #10504][ruby-core:66240] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22Fixed equality method fails when given the object that doesn't support table ↵hsbt
method. [Bug #12422][ruby-core:75707] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22Fixed to write_headers option behavior when given no rows.hsbt
[Bug #9988][ruby-core:63375] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22Escape skip_lines string before convert to Regexp.hsbt
It ignored all of lines when given Regexp special characters. [Feature #9147][ruby-core:58549] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-28csv.rb: fix incompatibility introduced in r59428glass
* lib/csv.rb: fix incompatibility introduced in r59428. CSV.new takes options as keyword arguments. * test/csv/test_features.rb: add a test to ensure it raises error againt unknown options * test/csv/test_features.rb: add a test to ensure row_sep option is properly applied git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-27csv.rb: use keyword parametersglass
* lib/csv.rb: usb keyword parameters to receive options * test/csv/test_features.rb: remove a test for checking options git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-27csv.rb: use Array#to_hglass
* lib/csv.rb (CSV::Row#to_hash): use Array#to_h git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-21Remove redundant square bracketskazu
Use character class directly instead of character class in character class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-18Improve CSV parsing performance.hsbt
Patch by @joshpencheon (Josh Pencheon) [fix GH-1607] #### benchmark-ips results ``` trunk: Warming up -------------------------------------- 4.000 i/100ms Calculating ------------------------------------- 39.661 (±10.1%) i/s - 2.352k in 60.034781s with-patch: Warming up -------------------------------------- 5.000 i/100ms Calculating ------------------------------------- 60.521 (± 9.9%) i/s - 3.595k in 60.047157s ``` #### memory_profiler resuts ``` trunk: allocated memory by class ----------------------------------- 35588490 String 7454320 Array 294000 MatchData 37340 Regexp 11840 Hash 2400 CSV 1600 Proc 1280 Method 800 StringIO with-patch: allocated memory by class ----------------------------------- 18788490 String 3454320 Array 294000 MatchData 37340 Regexp 11840 Hash 2400 CSV 1600 Proc 1280 Method 800 StringIO ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-17Optimize CSV#shift.hsbt
[Bug #12373][ruby-core:75462] Patch by Yuki Kurihara. Benchmark: ``` Warming up -------------------------------------- csv_shift 1.000 i/100ms new_csv_shift 1.000 i/100ms Calculating ------------------------------------- csv_shift 1.192 (± 0.0%) i/s - 6.000 in 5.034250s new_csv_shift 1.527 (± 0.0%) i/s - 8.000 in 5.243446s Comparison: new_csv_shift: 1.5 i/s csv_shift: 1.2 i/s - 1.28x slower ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-16Strip punctuation from CSV headers in symbol converter.hsbt
Patch by @cllns. [Fix GH-957] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-16Added accessor of original line when parsing.hsbt
[Feature #11865][ruby-core:72452][fix GH-1170] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-23csv.rb: fix field_size_limit checknobu
* lib/csv.rb (CSV#shift): the last column is an Array in extended column since r55985. [ruby-dev:49964] [Bug #13149] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-07* lib/csv.rb (CSV::{Row,Table}#{each,delete_if}): returns an enumeratorktsj
if no block is given. [ruby-core:75346] [Feature #11058] * test/csv/test_row.rb: add test for above. * test/csv/test_table.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-22csv.rb: performance with very long quoted linesnobu
* lib/csv.rb (CSV#shift): store partial quoted strings in an array and join at last, to improve performance with very long quoted lines. [ruby-core:76987] [Bug #12691] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-23Update documentation of CSV header converternobu
* lib/csv.rb: Update documentation of CSV header converter for r45498, [GH-575]. [Fix GH-1215] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-01Adding a liberal_parsing option to CSV. Patch by Braden Anderson.jeg2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-19csv.rb: Fix typo [ci skipnobu
* lib/csv.rb (CSV#initialize): [DOC] Fix double-word typo. [Fix GH-1161] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-18csv.rb: tail commasnobu
* lib/csv.rb (CSV::Converters, CSV::DEFAULT_OPTIONS): supply tail commas for further elements. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-18csv.rb: fix typonobu
* lib/csv.rb (CSV#shift): fix typo. [See GH-1160] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02csv.rb: fix encodingnobu
* lib/csv.rb: encoding must be plased at the first line except for shebang. [fix GH-1116] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02* lib/csv.rb: enable frozen_string_literal.hsbt
[fix GH-1116] Patch by @marshall-lee git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07* lib/csv.rb: typo fix [ci skip][fix GH-958] Patch by @henrikhsbt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17* lib/csv.rb: accept to use Range object for row selection.hsbt
[Feature #11267][ruby-dev:49091] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-10* Fix typo. Patch by @davydovantongogotanaka
[Fix GH-928][ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-01lib/csv.rb: [DOC] Fix typo [ci skip][Fix GH-907]gogotanaka
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-04* remove trailing spaces.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-04* lib/csv.rb: added documentation for skip_blanks option by @decasiahsbt
[fix GH-744][ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21* lib/csv.rb: avoid unnecessary object allocations.glass
patch is from Andrew Vit. [ruby-core:63215] [Feature #9952] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-10csv.rb: honor encoding optionnobu
* lib/csv.rb (CSV#<<): honor explicity given encoding. based on the patch by DAISUKE TANIWAKI <daisuketaniwaki AT gmail.com> at [ruby-core:62113]. [Bug #9766] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e