ntable 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ === 0.1.5 / 2012-09-24
2
+
3
+ * INCOMPATIBLE CHANGE: Renamed :postprocess option in NTable.from_nested_object to :postprocess_labels.
4
+ * NTable.from_nested_object learned :postprocess_range, which postprocesses a range for an IndexedAxis.
5
+ * NTable.from_nested_object raised NoSuchCellError if you used :postprocess_label to remove a label accessed in the data. Now the data is just thrown away silently.
6
+ * Calling decompose on a "shared" table (i.e. a slice previously obtained from decompose or shared_slice) yielded the wrong table. (The offset into the original table was incorrect.) Fixed.
7
+ * Implemented a slightly nicer inspect for each type.
8
+
1
9
  === 0.1.4 / 2012-09-24
2
10
 
3
11
  * NTable::Structure and NTable::AxisInfo are now Enumerable, letting you iterate over the axes and labels, respectively.
data/Version CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -119,13 +119,25 @@ module NTable
119
119
  # proc is provided, the resulting axis will be a LabeledAxis.
120
120
  # You can also pass true instead of a Proc; this will create an
121
121
  # LabeledAxis and make the conversion a simple to_s.
122
- # [<tt>:postprocess</tt>]
123
- # An optional Proc that postprocesses the final labels array.
124
- # It should take an array of labels and return a modified array
125
- # (which can be the original array modified in place). Called
126
- # after any sort has been completed.
122
+ # [<tt>:postprocess_labels</tt>]
123
+ # An optional Proc that postprocesses the final labels array, if
124
+ # a LabeledAxis or an ObjectAxis is being generated.
125
+ # It should take an array of labels and return the desired array.
126
+ # You may modify the array in place and return the original.
127
+ # This is called after any sort has been completed.
127
128
  # You can use this, for example, to "fill in" labels that were
128
129
  # not present in the original data.
130
+ # WARNING: if you remove labels from the array, any data in those
131
+ # locations will silently be lost.
132
+ # [<tt>:postprocess_range</tt>]
133
+ # An optional Proc that postprocesses the final integer range, if
134
+ # an IndexedAxis is being generated.
135
+ # It should take a Range of integer as an argument, and return
136
+ # either the original or a different Range.
137
+ # You can use this, for example, to extend the range of this axis
138
+ # beyond that for which data exists.
139
+ # WARNING: if you remove values from the range, any data in those
140
+ # locations will silently be lost.
129
141
  #
130
142
  # The third argument is an optional hash of miscellaneous options.
131
143
  # The following keys are recognized:
@@ -195,11 +207,17 @@ module NTable
195
207
  end
196
208
  labels_.sort!(&func_)
197
209
  end
198
- postprocess_ = field_[:postprocess]
199
- labels_ = postprocess_.call(labels_) if postprocess_.respond_to?(:call)
210
+ postprocess_ = field_[:postprocess_labels]
211
+ labels_ = postprocess_.call(labels_) || labels_ if postprocess_.respond_to?(:call)
200
212
  axis_ = klass_.new(labels_)
201
213
  when ::Array
202
- axis_ = IndexedAxis.new(ai_[1].to_i - ai_[0].to_i, ai_[0].to_i)
214
+ range_ = ((ai_[0].to_i)...(ai_[1].to_i))
215
+ postprocess_ = field_[:postprocess_range]
216
+ range_ = postprocess_.call(range_) || range_ if postprocess_.respond_to?(:call)
217
+ ai_[0] = range_.first.to_i
218
+ ai_[1] = range_.last.to_i
219
+ ai_[1] += 1 unless range_.exclude_end?
220
+ axis_ = IndexedAxis.new(ai_[1] - ai_[0], ai_[0])
203
221
  end
204
222
  struct_.add(axis_, name_) if axis_
205
223
  end
@@ -250,7 +268,10 @@ module NTable
250
268
 
251
269
  def _populate_nested_values(table_, path_, axis_data_, obj_) # :nodoc:
252
270
  if path_.size == table_.dim
253
- table_.set!(*path_, obj_)
271
+ begin
272
+ table_.set!(*path_, obj_)
273
+ rescue NoSuchCellError
274
+ end
254
275
  else
255
276
  case obj_
256
277
  when ::Hash
@@ -75,6 +75,14 @@ module NTable
75
75
  end
76
76
 
77
77
 
78
+ # Basic output.
79
+
80
+ def inspect
81
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{@axis_name}:#{@axis_object.class.name.sub('NTable::', '')}>"
82
+ end
83
+ alias_method :to_s, :inspect
84
+
85
+
78
86
  # The underlying axis implementation
79
87
  attr_reader :axis_object
80
88
 
@@ -178,6 +186,14 @@ module NTable
178
186
  end
179
187
 
180
188
 
189
+ # Basic output.
190
+
191
+ def inspect
192
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{coord_array.inspect}>"
193
+ end
194
+ alias_method :to_s, :inspect
195
+
196
+
181
197
  # Standard equality check
182
198
 
183
199
  def eql?(obj_)
@@ -280,6 +296,15 @@ module NTable
280
296
  end
281
297
 
282
298
 
299
+ # Basic output.
300
+
301
+ def inspect
302
+ axes_ = @indexes.map{ |a_| "#{a_.axis_name}:#{a_.axis_object.class.name.sub('NTable::', '')}" }
303
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{axes_.join(', ')}#{@parent ? ' (sub)' : ''}>"
304
+ end
305
+ alias_method :to_s, :inspect
306
+
307
+
283
308
  # Returns true if the two structures are equivalent, both in the
284
309
  # axes and in the parentage. The structure of a shared slice is not
285
310
  # equivalent, in this sense, to the "same" structure created from
@@ -84,6 +84,15 @@ module NTable
84
84
  end
85
85
 
86
86
 
87
+ # Basic output.
88
+
89
+ def inspect
90
+ axes_ = @structure.all_axes.map{ |a_| "#{a_.axis_name}:#{a_.axis_object.class.name.sub('NTable::', '')}" }
91
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{axes_.join(', ')}#{@parent ? ' (sub)' : ''} #{@vals.inspect}>"
92
+ end
93
+ alias_method :to_s, :inspect
94
+
95
+
87
96
  # Returns true if the two tables are equivalent, both in the data
88
97
  # and in the parentage. The structure of a shared slice is not
89
98
  # equivalent, in this sense, to the "same" table created from
@@ -525,7 +534,7 @@ module NTable
525
534
  vec_ = ::Array.new(outer_struct_.dim, 0)
526
535
  tables_ = (0...outer_struct_.size).map do |i_|
527
536
  t_ = Table.new(inner_struct_, :acquire => @vals,
528
- :offset => outer_struct_._compute_offset_for_vector(vec_),
537
+ :offset => @offset + outer_struct_._compute_offset_for_vector(vec_),
529
538
  :parent => self)
530
539
  outer_struct_._inc_vector(vec_)
531
540
  t_
@@ -98,6 +98,13 @@ module NTable
98
98
  end
99
99
 
100
100
 
101
+ def test_decompose_after_decompose
102
+ t1_ = Table.new(@structure_2d, :load => (2..21).to_a)
103
+ t2_ = t1_.decompose([1]).get(2).decompose([0]).get
104
+ assert_equal(Table.new(@structure_row, :load => [4, 5]), t2_)
105
+ end
106
+
107
+
101
108
  end
102
109
 
103
110
  end
@@ -140,6 +140,14 @@ module NTable
140
140
  end
141
141
 
142
142
 
143
+ def test_from_level_1_start_1_indexed_with_postprocess
144
+ obj_ = (1..12).to_a
145
+ t1_ = Table.from_nested_object(obj_,
146
+ [{:postprocess_range => ->(r_){ (1..10) }}])
147
+ assert_equal(Table.new(Structure.add(@indexed_axis_10), :load => (2..11).to_a), t1_)
148
+ end
149
+
150
+
143
151
  def test_from_level_2_indexed
144
152
  obj_ = [[nil, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], []]
145
153
  t1_ = Table.from_nested_object(obj_)
@@ -219,7 +227,7 @@ module NTable
219
227
  def test_from_level_1_labeled_with_objectify_and_postprocess
220
228
  obj_ = {:one => 1, :two => 2}
221
229
  t1_ = Table.from_nested_object(obj_,
222
- [{:sort => true, :objectify => true, :postprocess => ->(labels_){ labels_ << :three }}],
230
+ [{:sort => true, :objectify => true, :postprocess_labels => ->(labels_){ labels_ << :three }}],
223
231
  :fill => 0)
224
232
  assert_equal(Table.new(Structure.add(@object_axis_3), :load => [1,2,0]), t1_)
225
233
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: