Class: CAConstString
Overview
Read-only column of variable-length Strings: every element's bytes are
packed into one shared buffer, with a (start, end) byte-range pair per
element (the Arrow string layout).
Built through CArray.const_string. For a column with heavy duplication
(categorical labels) prefer CACategorical, which stores each distinct
value once.
Instance Method Summary
collapse
-
#categorize(labels: nil, sort_labels: false) ⇒ CACategorical
-
#difference(other, sort: false) ⇒ CAConstString
-
#intersection(other, sort: false) ⇒ CAConstString
-
#is_in(values) ⇒ CArray
-
#is_mode(axis: nil) ⇒ CArray
-
#locate_addr(ref) ⇒ CArray
-
#mask_duplicates(axis: nil) ⇒ CAConstString
-
#max(axis: nil, keep_axis: false) ⇒ String, CAConstString
Byte-largest counterpart of #min.
-
#max_index(axis: nil) ⇒ Integer, CArray
-
#min(axis: nil, keep_axis: false) ⇒ String, CAConstString
Returns the byte-smallest string, skipping masked cells; UNDEF when every cell is masked or the array is empty.
-
#min_index(axis: nil) ⇒ Integer, CArray
-
#minmax(axis: nil, keep_axis: false) ⇒ Array
-
#mode(axis: nil) ⇒ CAConstString, Array
-
#nunique(axis: nil, keep_axis: false) ⇒ Integer, CArray
-
#order(*args) ⇒ CArray
-
#partition_copy(kth, axis: nil) ⇒ CAConstString
-
#partition_index(kth, axis: nil) ⇒ CArray
-
#rank_index(axis: nil) ⇒ CArray
-
#sort(axis: nil, kind: :quick, masked_position: :last) ⇒ CAConstString
Returns a sorted CAConstString view, gathered over the same buffer and offsets.
-
#sort_addr(axis: nil, kind: :quick, masked_position: :last) ⇒ CArray
Returns the view-flat addresses that index a sort by string order.
-
#sort_copy(axis: nil, kind: :quick, masked_position: :last) ⇒ CAConstString
-
#sort_index(axis: nil, kind: :quick, masked_position: :last) ⇒ CArray
Returns the per-fiber indices that index a sort by string order.
-
#template(type = nil, **opts) ⇒ CArray
CAConstString is the one Face with three separate entities -- storage (int64 offset), surface (fixlen), and the length-prefixed buffer -- so it has no byte-compatible blank form (other Faces have surface == storage or a struct tail, which the core template lift handles).
-
#union(other, sort: false) ⇒ CAConstString
-
#unique(sort: false) ⇒ CAConstString
-
#value_counts(sort: false) ⇒ Array(CAConstString, CArray)
#bytesize, #capitalize, #center, #chomp, #delete_prefix, #delete_suffix, #downcase, #encode, #end_with?, #extract, #force_encoding, #gsub, #in?, #include?, #ljust, #lstrip, #match?, #rindex, #rjust, #rstrip, #scrub, #start_with?, #str_index, #str_len, #strip, #swapcase, #to_const_string, #to_f, #to_fixlen_string, #to_i, #to_string, #upcase
Instance Method Details
#categorize(labels: nil, sort_labels: false) ⇒ CACategorical
314
315
316
|
# File 'lib/carray/const_string.rb', line 314
def categorize (labels: nil, sort_labels: false)
to_string.categorize(labels: labels, sort_labels: sort_labels)
end
|
#difference(other, sort: false) ⇒ CAConstString
296
297
298
|
# File 'lib/carray/const_string.rb', line 296
def difference (other, sort: false)
const_string_lift(to_string.difference(string_operand(other), sort: sort))
end
|
#intersection(other, sort: false) ⇒ CAConstString
290
291
292
|
# File 'lib/carray/const_string.rb', line 290
def intersection (other, sort: false)
const_string_lift(to_string.intersection(string_operand(other), sort: sort))
end
|
#is_in(values) ⇒ CArray
284
285
286
|
# File 'lib/carray/const_string.rb', line 284
def is_in (values)
to_string.is_in(string_operand(values))
end
|
#is_mode(axis: nil) ⇒ CArray
272
273
274
|
# File 'lib/carray/const_string.rb', line 272
def is_mode (axis: nil)
to_string.is_mode(axis: axis)
end
|
#locate_addr(ref) ⇒ CArray
308
309
310
|
# File 'lib/carray/const_string.rb', line 308
def locate_addr (ref)
to_string.locate_addr(string_operand(ref))
end
|
#mask_duplicates(axis: nil) ⇒ CAConstString
278
279
280
|
# File 'lib/carray/const_string.rb', line 278
def mask_duplicates (axis: nil)
const_string_lift(to_string.mask_duplicates(axis: axis))
end
|
#max(axis: nil, keep_axis: false) ⇒ String, CAConstString
173
174
175
176
|
# File 'lib/carray/const_string.rb', line 173
def max (*args, **kw)
return __max_bytes__ || UNDEF if args.empty? && kw.empty?
const_string_lift(to_string.max(*args, **kw))
end
|
#max_index(axis: nil) ⇒ Integer, CArray
193
194
195
|
# File 'lib/carray/const_string.rb', line 193
def max_index (*args, **kw)
to_string.max_index(*args, **kw)
end
|
#min(axis: nil, keep_axis: false) ⇒ String, CAConstString
165
166
167
168
|
# File 'lib/carray/const_string.rb', line 165
def min (*args, **kw)
return __min_bytes__ || UNDEF if args.empty? && kw.empty?
const_string_lift(to_string.min(*args, **kw))
end
|
#min_index(axis: nil) ⇒ Integer, CArray
187
188
189
|
# File 'lib/carray/const_string.rb', line 187
def min_index (*args, **kw)
to_string.min_index(*args, **kw)
end
|
#minmax(axis: nil, keep_axis: false) ⇒ Array
180
181
182
183
|
# File 'lib/carray/const_string.rb', line 180
def minmax (*args, **kw)
return [min, max] if args.empty? && kw.empty?
to_string.minmax(*args, **kw).map { |r| const_string_lift(r) }
end
|
265
266
267
268
|
# File 'lib/carray/const_string.rb', line 265
def mode (axis: nil)
r = to_string.mode(axis: axis)
r.is_a?(Array) ? r.map { |c| const_string_lift(c) } : const_string_lift(r)
end
|
#nunique(axis: nil, keep_axis: false) ⇒ Integer, CArray
259
260
261
|
# File 'lib/carray/const_string.rb', line 259
def nunique (axis: nil, keep_axis: false)
to_string.nunique(axis: axis, keep_axis: keep_axis)
end
|
#order(*args) ⇒ CArray
157
158
159
|
# File 'lib/carray/const_string.rb', line 157
def order (*args, **kw)
to_string.order(*args, **kw)
end
|
#partition_copy(kth, axis: nil) ⇒ CAConstString
199
200
201
|
# File 'lib/carray/const_string.rb', line 199
def partition_copy (*args, **kw)
const_string_lift(to_string.partition_copy(*args, **kw))
end
|
#partition_index(kth, axis: nil) ⇒ CArray
205
206
207
|
# File 'lib/carray/const_string.rb', line 205
def partition_index (*args, **kw)
to_string.partition_index(*args, **kw)
end
|
#rank_index(axis: nil) ⇒ CArray
151
152
153
|
# File 'lib/carray/const_string.rb', line 151
def rank_index (*args, **kw)
to_string.rank_index(*args, **kw)
end
|
#sort(axis: nil, kind: :quick, masked_position: :last) ⇒ CAConstString
119
120
121
122
|
# File 'lib/carray/const_string.rb', line 119
def sort (*args, **kw)
addr = sort_addr(*args, **kw)
kw[:axis].nil? ? self[addr.flatten] : self[addr]
end
|
#sort_addr(axis: nil, kind: :quick, masked_position: :last) ⇒ CArray
135
136
137
138
139
140
|
# File 'lib/carray/const_string.rb', line 135
def sort_addr (*args, **kw)
return __sort_addr_bytes__ if args.empty? && kw.empty? && ! has_mask?
to_string.sort_addr(*args, **kw)
end
|
#sort_copy(axis: nil, kind: :quick, masked_position: :last) ⇒ CAConstString
128
129
130
|
# File 'lib/carray/const_string.rb', line 128
def sort_copy (*args, **kw)
sort(*args, **kw).copy
end
|
#sort_index(axis: nil, kind: :quick, masked_position: :last) ⇒ CArray
145
146
147
|
# File 'lib/carray/const_string.rb', line 145
def sort_index (*args, **kw)
to_string.sort_index(*args, **kw)
end
|
#template(type = nil, **opts) ⇒ CArray
CAConstString is the one Face with three separate entities -- storage
(int64 offset), surface (fixlen), and the length-prefixed buffer -- so it
has no byte-compatible blank form (other Faces have surface == storage or
a struct tail, which the core template lift handles). A same-class
template would be an unusable shell, so override it: with an explicit type
defer to the generic (plain) path; with no type return a plain same-shape
object array (a fillable string container), honouring a block.
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/carray/const_string.rb', line 218
def template (*args, &block)
return super unless args.empty? out = CArray.object(*shape)
if block
if block.arity == 0
out[] = block.call
else
out.map_with_index! { |_, *idx| block.call(*idx) }
end
end
out
end
|
#union(other, sort: false) ⇒ CAConstString
302
303
304
|
# File 'lib/carray/const_string.rb', line 302
def union (other, sort: false)
const_string_lift(to_string.union(string_operand(other), sort: sort))
end
|
246
247
248
|
# File 'lib/carray/const_string.rb', line 246
def unique (sort: false)
const_string_lift(to_string.unique(sort: sort))
end
|
252
253
254
255
|
# File 'lib/carray/const_string.rb', line 252
def value_counts (sort: false)
values, counts = to_string.value_counts(sort: sort)
[const_string_lift(values), counts]
end
|