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
-
#mode(axis: nil) ⇒ CAConstString, Array
-
#nunique(axis: nil, keep_axis: false) ⇒ Integer, CArray
-
#sort ⇒ CAConstString
Returns a byte-order sorted view built by gathering the offsets with sort_index.
-
#sort_copy ⇒ CAConstString
-
#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
218
219
220
|
# File 'lib/carray/const_string.rb', line 218
def categorize (labels: nil, sort_labels: false)
to_string.categorize(labels: labels, sort_labels: sort_labels)
end
|
#difference(other, sort: false) ⇒ CAConstString
200
201
202
|
# File 'lib/carray/const_string.rb', line 200
def difference (other, sort: false)
to_string.difference(string_operand(other), sort: sort).to_const_string
end
|
#intersection(other, sort: false) ⇒ CAConstString
194
195
196
|
# File 'lib/carray/const_string.rb', line 194
def intersection (other, sort: false)
to_string.intersection(string_operand(other), sort: sort).to_const_string
end
|
#is_in(values) ⇒ CArray
188
189
190
|
# File 'lib/carray/const_string.rb', line 188
def is_in (values)
to_string.is_in(string_operand(values))
end
|
#is_mode(axis: nil) ⇒ CArray
176
177
178
|
# File 'lib/carray/const_string.rb', line 176
def is_mode (axis: nil)
to_string.is_mode(axis: axis)
end
|
#locate_addr(ref) ⇒ CArray
212
213
214
|
# File 'lib/carray/const_string.rb', line 212
def locate_addr (ref)
to_string.locate_addr(string_operand(ref))
end
|
#mask_duplicates(axis: nil) ⇒ CAConstString
182
183
184
|
# File 'lib/carray/const_string.rb', line 182
def mask_duplicates (axis: nil)
to_string.mask_duplicates(axis: axis).to_const_string
end
|
165
166
167
168
169
170
171
172
|
# File 'lib/carray/const_string.rb', line 165
def mode (axis: nil)
r = to_string.mode(axis: axis)
case r
when CArray then r.to_const_string
when Array then r.map { |c| c.is_a?(CArray) ? c.to_const_string : c }
else r
end
end
|
#nunique(axis: nil, keep_axis: false) ⇒ Integer, CArray
159
160
161
|
# File 'lib/carray/const_string.rb', line 159
def nunique (axis: nil, keep_axis: false)
to_string.nunique(axis: axis, keep_axis: keep_axis)
end
|
97
98
99
|
# File 'lib/carray/const_string.rb', line 97
def sort
self[sort_index]
end
|
105
106
107
|
# File 'lib/carray/const_string.rb', line 105
def sort_copy
self[sort_index].copy
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.
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/carray/const_string.rb', line 118
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
206
207
208
|
# File 'lib/carray/const_string.rb', line 206
def union (other, sort: false)
to_string.union(string_operand(other), sort: sort).to_const_string
end
|
146
147
148
|
# File 'lib/carray/const_string.rb', line 146
def unique (sort: false)
to_string.unique(sort: sort).to_const_string
end
|
152
153
154
155
|
# File 'lib/carray/const_string.rb', line 152
def value_counts (sort: false)
values, counts = to_string.value_counts(sort: sort)
[values.to_const_string, counts]
end
|