easy_sheet_io 0.4.8.2 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c96b508dacc94ed1f5627c6a5b40f2282d08178a54b9114201d818a88752984d
4
- data.tar.gz: 3b028f6e872d98c4f9dd5405a5a9278e439893270442a87d35d50823ae756e29
3
+ metadata.gz: d7640c37216da2bfd884b84c614c924e0a3eca722a357c2ccca408e9fee42fc8
4
+ data.tar.gz: '0668281347c6848a0cdde66ff3e9db439202ae1c476807f5dbaa75a73f5415b6'
5
5
  SHA512:
6
- metadata.gz: ef3207db108cee37db118c5ec8e73b05bd43fd721f1a2685f88abf2e8a73d2ea780c42cdef37169b9bdfa221e7ca6afa53c67871f2e42e154b9f480e6b6a75b8
7
- data.tar.gz: e3bc6a74cb7f4fca7602b5c4a9f1cb3d1eac21e35b492b0303080ee9fc700536b3fb0b7750b9ec1c8412203edca5e2579791926e02ec4f76fafbb168d11d3b0b
6
+ metadata.gz: 2a7b3ab88ee7f34796898fe59db951d83d1c02c6c4d84aee9bba216abe5b3c57cfd2810b60d5af831a0b28459a6086d8539bbdf736781b6e5eaef09a3b46ba00
7
+ data.tar.gz: 9eed84c33a92b0f653241928bdccb10a070615767832820acf3ea14343d06a25527597c86d007b3dfd61c64b81d14c32a9dc4e82bcdeb432ab477f65ff70af57
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.4.8.2"
4
+ VERSION = "0.4.9"
5
5
  end
data/lib/easy_sheet_io.rb CHANGED
@@ -37,14 +37,21 @@ module EasySheetIo
37
37
  if format.to_s == "array"
38
38
  return csv
39
39
  elsif format.to_s == "hash"
40
- return to_hash(csv, **opt)
40
+ h, i = to_hash(csv, **opt)
41
+ return h
41
42
  else # include format.nil? (in this case, convert to Daru::DF).
42
- ans = to_df(to_hash(csv, **opt), format: format)
43
+
44
+ h, ind_orig = to_hash(csv, index: index, **opt)
45
+ ans = to_df(h, format: format)
43
46
 
44
47
  # Converting Encode and Setting index.. rover not supported yet
45
48
  if format.to_s == "daru" || format.nil?
46
49
  ans.convert_enc!(from: encoding, to: "utf-8")
47
- ans.set_index!(index) if index
50
+ begin
51
+ ans.index = ind_orig if index
52
+ rescue
53
+ warn "Indexing failed (Parhaps due to duplicated index)."
54
+ end
48
55
  end
49
56
 
50
57
  return ans
@@ -59,11 +66,17 @@ module EasySheetIo
59
66
  if format.to_s == "array"
60
67
  return a2d
61
68
  elsif format.to_s == "hash"
62
- return to_hash(a2d, **opt)
69
+ h, i = to_hash(a2d, **opt)
70
+ return h
63
71
  else # include format.nil?
64
- ans = to_df(to_hash(a2d, **opt), format: format)
72
+ h, ind_orig = to_hash(a2d, index: index, **opt)
73
+ ans = to_df(h, format: format)
65
74
  if format.to_s == "daru" || format.nil?
66
- ans.set_index!(index) if index
75
+ begin
76
+ ans.index = ind_orig if index
77
+ rescue
78
+ warn "Indexing failed (Parhaps due to duplicated index)."
79
+ end
67
80
  end
68
81
  return ans
69
82
  end
@@ -75,7 +88,8 @@ module EasySheetIo
75
88
  def to_hash(array2d, line_from: 1, line_until: nil, line_ignored: nil,
76
89
  column_from: nil, column_until: nil,
77
90
  header: 0, symbol_header: false,
78
- replaced_by_nil: [], analyze_type: true)
91
+ replaced_by_nil: [], analyze_type: true,
92
+ index: nil)
79
93
  ## TODO.. column_from: , column_until:
80
94
 
81
95
  # Define Read Range------------
@@ -91,6 +105,10 @@ module EasySheetIo
91
105
  # And get originally array-----
92
106
  output = array2d[lfrom...luntil]
93
107
  # -----------------------------
108
+
109
+ # Then get data of index-------
110
+ ind_orig = index ? output.map{ _1[index] } : nil
111
+ # -----------------------------
94
112
 
95
113
  # Selecct Column---------------
96
114
  output = output.map { _1[column_from...column_until] } if column_from || column_until
@@ -112,12 +130,16 @@ module EasySheetIo
112
130
  # -----------------------------
113
131
 
114
132
  # Make Hash(Header => Data Array)
115
- return hd.each_with_object({}).with_index {|(hdr, hash), i| hash[hdr]=output_transpose[i]}
133
+ return hd.each_with_object({}).with_index {|(hdr, hash), i| hash[hdr]=output_transpose[i]}, ind_orig
116
134
  end
117
135
 
118
136
  # Convert Hash to DataFrame
119
137
  def to_df(d, format: :daru)
120
- return format.to_s == "daru" || format.nil? ? Daru::DataFrame.new(d) : Rover::DataFrame.new(d)
138
+ if format.to_s == "daru" || format.nil?
139
+ Daru::DataFrame.new(d)
140
+ else
141
+ Rover::DataFrame.new(d)
142
+ end
121
143
  end
122
144
 
123
145
  #----------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_sheet_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8.2
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - show-o-atakun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-28 00:00:00.000000000 Z
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daru