carray 3.0.6 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1504
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +8 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +73 -72
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. data/lib/carray/data_type_limits.rb +0 -91
@@ -26,14 +26,37 @@ class CAFrame
26
26
  # rows), so the answer is about the type and not the data: a refusal
27
27
  # there means the operation does not apply, while an error in the verb
28
28
  # itself is left to raise. An object column is the exception: its type
29
- # says nothing of what it holds, so one with no present value is left out
30
- # of a verb run over every column. An N-D column (each row a profile) is
29
+ # says nothing of what it holds, so one with no present value, or whose
30
+ # cells do not answer, is left out of a verb run over every column. An N-D column (each row a profile) is
31
31
  # asked, and computed, along the rows.
32
32
  module ColumnVerbs
33
33
 
34
34
  private
35
35
 
36
- def over_named_columns (verb, names, key_names, args = [], keywords = {})
36
+ # The row of each cell, UNDEF where the cell is masked: a first or last
37
+ # taken of it picks the row, and the row picks the value of a Face that
38
+ # cannot hold new values, as lag picks it.
39
+ def present_rows(col)
40
+ rows = CArray.int64(col.elements).seq
41
+ rows[col.is_masked] = UNDEF if col.has_mask?
42
+ rows
43
+ end
44
+
45
+ # A verb whose answers lie on the frame's rows, with no column to compute:
46
+ # a frame of no column would also have no row.
47
+ def refuse_no_column_on_rows(verb, out, nrow)
48
+ return unless out.is_a?(Hash) && out.empty? && nrow > 0
49
+ raise ArgumentError, "#{verb}: no column to compute (every column is a key or has no #{verb})"
50
+ end
51
+
52
+ def refuse_unknown_fill_columns(verb, fills)
53
+ return unless fills.is_a?(Hash)
54
+ unknown = fills.keys - @frame.column_names
55
+ return if unknown.empty?
56
+ raise ArgumentError, "#{verb}: fill_value names no column #{unknown.map(&:inspect).join(', ')}"
57
+ end
58
+
59
+ def over_named_columns(verb, names, key_names, args = [], keywords = {})
37
60
  if names.empty?
38
61
  cols = {}
39
62
  @frame.column_names.each do |name|
@@ -41,7 +64,8 @@ class CAFrame
41
64
  col = @frame[name]
42
65
  next if valueless_object_column?(col, verb, args)
43
66
  next unless column_has?(col, verb, args, keywords)
44
- cols[name] = yield(col, name)
67
+ cols[name] = answer_of_every_column(col, name) { |c, n| yield(c, n) }
68
+ cols.delete(name) if cols[name].equal?(NO_ANSWER)
45
69
  end
46
70
  return cols
47
71
  end
@@ -50,7 +74,7 @@ class CAFrame
50
74
  names.map { |name| @frame.__send__(:column_key, name, verb) }, verb)
51
75
  results = keys.map do |key|
52
76
  name = key
53
- col = @frame[key]
77
+ col = @frame.__send__(:named_column, key, verb)
54
78
  unless column_has?(col, verb, args, keywords)
55
79
  raise CArray::DataTypeError,
56
80
  "#{verb}: column #{name.inspect} " \
@@ -61,11 +85,54 @@ class CAFrame
61
85
  results.size == 1 ? results.first : keys.zip(results).to_h
62
86
  end
63
87
 
88
+ NO_ANSWER = Object.new.freeze
89
+ private_constant :NO_ANSWER
90
+
91
+ # What an object column holds shows only in the verb itself: one whose
92
+ # cells do not answer is left out of a verb run over every column, as a
93
+ # column of a type without the operation is, wherever those cells sit.
94
+ # refuse_wrong_reduction_arguments has refused what no column would take.
95
+ def answer_of_every_column(col, name)
96
+ return yield(col, name) if col.face? || col.data_type != CA_OBJECT
97
+ begin
98
+ yield(col, name)
99
+ rescue TypeError, ArgumentError, NoMethodError, RangeError
100
+ NO_ANSWER
101
+ end
102
+ end
103
+
104
+ # The keywords of first / last / nunique / count / all / any: all and any
105
+ # take skip_masked:, as CArray#all / #any do, and the others none.
106
+ # Without **keywords on those verbs Ruby would hand a keyword in as a
107
+ # column name.
108
+ def value_reduction_keywords(verb, keywords)
109
+ allowed = %i[all any].include?(verb) ? [:skip_masked] : []
110
+ unknown = keywords.keys - allowed
111
+ return keywords if unknown.empty?
112
+ raise ArgumentError,
113
+ "unknown keyword#{unknown.size > 1 ? "s" : ""}: " + unknown.map(&:inspect).join(", ")
114
+ end
115
+
116
+ # The arguments of a reduction, asked of the core on a number before any
117
+ # column, so a wrong one is not taken for a column that does not answer.
118
+ # fill_value: is of each column's type, and stays out of this.
119
+ def refuse_wrong_reduction_arguments(verb, args, keywords)
120
+ return if verb == :count
121
+ CArray.float64(1).public_send(verb, *args, **keywords.reject { |k, _| k == :fill_value })
122
+ rescue CArray::DataTypeError, NoMethodError
123
+ nil
124
+ end
125
+
64
126
  # An object column with no present cell says nothing of what it holds,
65
127
  # so a verb run over every column leaves it out, as select leaves it out
66
- # of every kind; counting the present cells applies to any column.
67
- def valueless_object_column? (col, verb, args)
68
- return false if col.face? || col.data_type != CA_OBJECT
128
+ # of every kind; counting the present cells applies to any column. A
129
+ # Face kept in object cells (a CAString) with rows, every one masked, is
130
+ # the same: the type would be asked of masked cells only, which answer
131
+ # with the identity whatever the type. With no rows the type is asked of
132
+ # blank cells of its kind.
133
+ def valueless_object_column?(col, verb, args)
134
+ return false if col.data_type != CA_OBJECT
135
+ return false if col.face? && col.elements == 0
69
136
  return false if %i[count_not_masked count_masked].include?(verb)
70
137
  return false if verb == :count && args.empty?
71
138
  col.count_not_masked == 0
@@ -74,7 +141,7 @@ class CAFrame
74
141
  # count with no value counts the present cells, which every type has;
75
142
  # a Face's own count takes a value (CACategorical#count(label)), so the
76
143
  # type is asked about count_not_masked instead.
77
- def column_has? (col, verb, args, keywords)
144
+ def column_has?(col, verb, args, keywords)
78
145
  verb = :count_not_masked if verb == :count && args.empty?
79
146
  # Two cells: one cell does not reach what combines two (a String's
80
147
  # median interpolates, its sum adds), and an empty column answers
@@ -1,4 +1,4 @@
1
- # CAFrame row concatenation (memo §5, spine = addressing + gather).
1
+ # CAFrame row concatenation (memo §5; the core is addressing + gather).
2
2
  #
3
3
  # Two entry points, mirroring the CArray-level taxonomy:
4
4
  #
@@ -52,10 +52,13 @@ class CAFrame
52
52
  index_pieces(frames, verb: "meld")
53
53
  check_trailing_shapes(frames, names, verb: "meld")
54
54
  frames = frames_with_rows(frames)
55
+ if first.index
56
+ check_same_column_type(frames.map(&:index), first.axis_name, verb: "meld")
57
+ end
55
58
  cols = {}
56
59
  names.each do |name|
57
60
  check_same_column_type(frames.map { |f| f[name] }, name, verb: "meld")
58
- cols[name] = CArray.meld(frames.map { |f| f[name] }, axis: 0)
61
+ cols[name] = welding_column(name, "meld") { CArray.meld(frames.map { |f| f[name] }, axis: 0) }
59
62
  end
60
63
  new(cols, axis_name: first.axis_name, index: meld_index(frames))
61
64
  end
@@ -85,7 +88,9 @@ class CAFrame
85
88
  frames = frames_with_rows(frames)
86
89
  cols = {}
87
90
  names.each do |name|
88
- cols[name] = CArray.concatenate(frames.map { |f| f[name] })
91
+ pieces = face_pieces_in_one_state(frames.map { |f| f[name] })
92
+ refuse_rounded_pieces(pieces, "concatenate", "column #{name.inspect}")
93
+ cols[name] = welding_column(name, "concatenate") { CArray.concatenate(pieces) }
89
94
  end
90
95
  new(cols, axis_name: first.axis_name, index: concatenate_index(frames))
91
96
  end
@@ -135,7 +140,8 @@ class CAFrame
135
140
  "stack: axis #{axis} out of range for column #{name.inspect} " \
136
141
  "(a #{parts.first.ndim}-D column takes 1 to #{parts.first.ndim})"
137
142
  end
138
- cols[name] = CArray.stack(parts, axis: axis)
143
+ refuse_rounded_pieces(parts, "stack", "column #{name.inspect}")
144
+ cols[name] = welding_column(name, "stack") { CArray.stack(parts, axis: axis) }
139
145
  end
140
146
  new(cols, axis_name: first.axis_name, index: first.index)
141
147
  end
@@ -194,6 +200,43 @@ class CAFrame
194
200
 
195
201
  # ---- shared validators -------------------------------------------------
196
202
 
203
+ # Pieces of one Face in different states brought to one, as an outer join
204
+ # brings its two keys: times and durations to a common unit, categoricals
205
+ # to the labels of all, the first piece's first.
206
+ def self.face_pieces_in_one_state(pieces)
207
+ first = pieces.first
208
+ return pieces unless first.face? && pieces.all? { |p| p.class == first.class }
209
+ # names-check: units, not names
210
+ if first.respond_to?(:in_common_unit_with, true) && pieces.map(&:unit).uniq.size > 1
211
+ common = pieces.drop(1).reduce(first) { |acc, p| acc.send(:in_common_unit_with, p).first }
212
+ return pieces.map { |p| p.unit == common.unit ? p : p.to_unit(common.unit) }
213
+ end
214
+ # names-check: label lists, not names
215
+ if first.is_a?(CACategorical) && pieces.map(&:labels).uniq.size > 1
216
+ labels = pieces.map(&:labels).reduce(:|)
217
+ return pieces.map { |p| CArray.object(*p.shape) { p.to_a }.categorize(labels: labels) }
218
+ end
219
+ pieces
220
+ end
221
+ private_class_method :face_pieces_in_one_state
222
+
223
+ # Pieces brought to a float: a value it rounds would be another value.
224
+ def self.refuse_rounded_pieces(pieces, verb, what)
225
+ return if pieces.size < 2 || pieces.any?(&:face?) || pieces.any? { |c| c.data_type == CA_FIXLEN }
226
+ refuse_rounded_integers(pieces, CArray.result_type(*pieces), verb, what)
227
+ end
228
+ private_class_method :refuse_rounded_pieces
229
+
230
+ # A refusal of the pieces reads as the verb the frames were given to, with
231
+ # the column it came from.
232
+ def self.welding_column(name, verb)
233
+ yield
234
+ rescue ArgumentError, CArray::DataTypeError => e
235
+ raise unless e.message.start_with?("#{verb}: ", "can't promote", "CAStack parents")
236
+ raise e.class, "#{verb}: column #{name.inspect}: #{e.message.delete_prefix("#{verb}: ")}"
237
+ end
238
+ private_class_method :welding_column
239
+
197
240
  def self.check_concat_inputs(frames, verb:)
198
241
  raise ArgumentError, "#{verb} requires at least one frame" if frames.empty?
199
242
  unless frames.all? { |f| f.is_a?(CAFrame) }
@@ -267,8 +310,7 @@ class CAFrame
267
310
  def self.meld_index(frames)
268
311
  indexes, axis = index_pieces(frames, verb: "meld")
269
312
  return nil unless indexes
270
- axis # unused; kept for symmetry
271
- CArray.meld(indexes, axis: 0)
313
+ welding_column(axis, "meld") { CArray.meld(indexes, axis: 0) }
272
314
  end
273
315
  private_class_method :meld_index
274
316
 
@@ -276,7 +318,9 @@ class CAFrame
276
318
  def self.concatenate_index(frames)
277
319
  indexes, _axis = index_pieces(frames, verb: "concatenate")
278
320
  return nil unless indexes
279
- CArray.concatenate(indexes)
321
+ indexes = face_pieces_in_one_state(indexes)
322
+ refuse_rounded_pieces(indexes, "concatenate", "the index")
323
+ welding_column(frames.first.axis_name, "concatenate") { CArray.concatenate(indexes) }
280
324
  end
281
325
  private_class_method :concatenate_index
282
326
 
@@ -65,6 +65,7 @@ class CAFrame
65
65
  # handed over. Cast the frame first (+df.cast+) when the promoted matrix is
66
66
  # what should be written to.
67
67
  def to_ca(writable: false)
68
+ writable = CArray.send(:bool_arg, writable, "writable", "to_ca")
68
69
  cols = @columns.values
69
70
  raise ArgumentError, "frame has no columns to stack into a matrix" if cols.empty?
70
71
  nd = @columns.find { |_, c| c.ndim != 1 }
@@ -152,7 +153,7 @@ class CArray
152
153
  # @raise [ArgumentError] when `axis` is out of range or is the row axis,
153
154
  # when the number of names differs from the length of `axis`, or when
154
155
  # a name repeats.
155
- def to_frame (*names, axis: -1)
156
+ def to_frame(*names, axis: -1)
156
157
  axis = -1 if axis.nil?
157
158
  if ndim < 2
158
159
  raise ArgumentError,
@@ -58,6 +58,8 @@ class CAFrame
58
58
  super(detail)
59
59
  end
60
60
 
61
+ # @return [String] the detail, with the file and the line it was
62
+ # found at in front when they are known.
61
63
  def message
62
64
  return super if @detail.nil?
63
65
  where =
@@ -99,16 +101,27 @@ class CAFrame
99
101
  class Tokenizer
100
102
  attr_reader :sep, :quote, :strip
101
103
 
102
- def initialize(sep, quote, strip)
104
+ # What a separator and a quote have to be, for reading and for writing.
105
+ def self.check_delimiters(sep, quote)
103
106
  unless sep.is_a?(String) && !sep.empty?
104
107
  raise ArgumentError, "sep: must be a non-empty String (got #{sep.inspect})"
105
108
  end
109
+ if sep.match?(/[\r\n]/)
110
+ raise ArgumentError, "sep: cannot hold a line end (got #{sep.inspect})"
111
+ end
106
112
  unless quote.is_a?(String) && quote.size == 1
107
113
  raise ArgumentError, "quote: must be one character (got #{quote.inspect})"
108
114
  end
115
+ if quote.match?(/[\r\n]/)
116
+ raise ArgumentError, "quote: cannot be a line end (got #{quote.inspect})"
117
+ end
109
118
  if sep.include?(quote)
110
119
  raise ArgumentError, "sep: #{sep.inspect} cannot contain the quote character"
111
120
  end
121
+ end
122
+
123
+ def initialize(sep, quote, strip)
124
+ Tokenizer.check_delimiters(sep, quote)
112
125
  @sep = sep
113
126
  @quote = quote
114
127
  @strip = strip
@@ -239,7 +252,7 @@ class CAFrame
239
252
  part = part + @sep + parts[i]
240
253
  end
241
254
  inner = part[1...-1]
242
- fields << (inner.include?(@quote) ? inner.gsub(@qq, @quote) : inner)
255
+ fields << (inner.include?(@quote) ? inner.gsub(@qq) { @quote } : inner)
243
256
  elsif part.include?(@quote)
244
257
  return nil
245
258
  else
@@ -438,7 +451,7 @@ class CAFrame
438
451
  CAFrame.__send__(:column_key, c, "read_csv", "columns: a column name") if c.is_a?(Symbol)
439
452
  next if c.is_a?(Integer) && c >= 0
440
453
  next if c.is_a?(Range) && (c.begin.nil? || (c.begin.is_a?(Integer) && c.begin >= 0)) &&
441
- (c.end.nil? || c.end.is_a?(Integer))
454
+ (c.end.nil? || (c.end.is_a?(Integer) && c.end >= 0))
442
455
  raise ArgumentError, "read_csv: columns: takes column names, or indexes from 0 " \
443
456
  "and Ranges of them (got #{c.inspect})"
444
457
  end
@@ -485,6 +498,7 @@ class CAFrame
485
498
  return nil if last.nil? && ncol.nil?
486
499
  last = ncol - 1 if last.nil?
487
500
  last -= 1 if c.end && c.exclude_end?
501
+ raise ArgumentError, "read_csv: columns: #{c.inspect} selects no column" if last < first
488
502
  (first..last).to_a
489
503
  end
490
504
  end
@@ -653,7 +667,7 @@ class CAFrame
653
667
 
654
668
  private def body_in_c(last = nil, chunk_bytes = CHUNK_BYTES)
655
669
  return read_body_into_const_string_columns if last.nil? && @read_text_as_const_string
656
- chunked = last.nil? && @names && @io.respond_to?(:external_encoding) &&
670
+ chunked = last.nil? && @names && @io.respond_to?(:internal_encoding) &&
657
671
  @io.internal_encoding.nil?
658
672
  # Names that have to agree with the first record leave its column
659
673
  # count to C, to be checked against them.
@@ -761,7 +775,7 @@ class CAFrame
761
775
  # The attributes the named headers give the columns +result+ returns, as
762
776
  # [{key => value}, ...] in the same order. A column of the file the
763
777
  # selection left out takes no part.
764
- def column_attrs (ncol)
778
+ def column_attrs(ncol)
765
779
  return nil unless @named_headers
766
780
  indexes = @selection ? selected_indexes(@names, ncol) : (0...ncol).to_a
767
781
  attrs = indexes.map { {} }
@@ -816,4 +830,5 @@ class CAFrame
816
830
  [names, table]
817
831
  end
818
832
  end
833
+ private_constant :CSVReader
819
834
  end
@@ -13,14 +13,14 @@
13
13
  class CAFrame
14
14
  # Raised when the contents of a column cannot be read as asked: a cell
15
15
  # that does not read as the type a +cast+ (or +read_csv+'s +types:+) asks
16
- # for under on_error: :raise, a cell +parse_to_time+ cannot read, a column
17
- # whose time format +infer_time_format+ / parse_to_time(name, :infer)
16
+ # for under on_error: :raise, a cell +parse_time+ cannot read, a column
17
+ # whose time format +infer_time_format+ / parse_time(name, :infer)
18
18
  # cannot find, or a float column +to_time+ cannot read as whole counts.
19
19
  # The message names the column and the cell. The arguments were fine; the
20
20
  # column's contents are what did not read.
21
21
  class UnreadableColumn < StandardError; end
22
22
 
23
- # Raised when +infer_time_format+ / parse_to_time(name, :infer) finds more
23
+ # Raised when +infer_time_format+ / parse_time(name, :infer) finds more
24
24
  # than one format every cell fits ("01/02/2024" and "03/04/2024" are both
25
25
  # day-first and month-first). The text reads in each of them, so it is
26
26
  # not an UnreadableColumn; +formats+ gives the candidates, to choose one and
@@ -43,6 +43,7 @@ class CAFrame
43
43
  # @!visibility private
44
44
  DEFAULT_AXIS_NAME = "row"
45
45
  Ractor.make_shareable(DEFAULT_AXIS_NAME)
46
+ private_constant :DEFAULT_AXIS_NAME
46
47
 
47
48
  # Build a frame from a Hash of +name => column+. Columns may be CArrays or
48
49
  # anything that answers +to_ca+ (Ruby Array, lazy view). All columns must
@@ -192,9 +193,8 @@ class CAFrame
192
193
  end
193
194
  end
194
195
 
195
- # A Ruby Array is no df[] key, read or written: CArray reads one as
196
- # [start, count], where [0, 2] would be rows 0 and 1 rather than rows 0
197
- # and 2. Says what to write for what the Array holds.
196
+ # A Ruby Array is no df[] key, read or written, as it is no CArray index
197
+ # either. Says what to write for what the Array holds.
198
198
  private def refuse_array_key(key, verb = "df[]")
199
199
  strings = !key.empty? && key.all? { |k| k.is_a?(String) }
200
200
  hint = if strings && verb == "df[]"
@@ -229,8 +229,8 @@ class CAFrame
229
229
  # +sel+ is a row-axis indexer key, classified exactly as CArray classifies a
230
230
  # 1-D column key (docs/topics/Indexer_decision_tree.md): a slice (BLOCK —
231
231
  # Range / ArithmeticSequence), a boolean CArray (SELECT), an integer CArray
232
- # (GRID), or an Integer (a single row). A Ruby Array, which the column
233
- # indexer would read as [start, count], is refused, as df[] refuses it.
232
+ # (GRID), or an Integer (a single row). A Ruby Array, which is no index,
233
+ # is refused, as df[] refuses it.
234
234
  # Mask and delete take the others and are forwarded to the column indexer,
235
235
  # so their errors match the rest of CArray. Splice reuses the same
236
236
  # classifier (CArray.scan_index) but needs a contiguous slice, so it takes
@@ -384,7 +384,7 @@ class CAFrame
384
384
  # column arriving from outside the frame has its axis-0 length checked
385
385
  # (§12-A); the conversions in verbs.rb rebind +@columns+ directly and rely on
386
386
  # being length-preserving instead. It is a replacement rather than an edit,
387
- # which is what sets it apart from the rest: +fill+ / +mask_eq+ /
387
+ # which is what sets it apart from the rest: +unmask+ / +mask+ /
388
388
  # +df[rows] = UNDEF+ write to the shared column and are therefore visible
389
389
  # wherever it is held, while this binds the name to a different column and
390
390
  # leaves the old one alone (the same rule +cast+ follows, for the physical
@@ -452,8 +452,7 @@ class CAFrame
452
452
  # :timedelta CATimedelta
453
453
  # :categorical CACategorical
454
454
  # or a data type as cast names it (:float64, :int32, :boolean, ...), which
455
- # picks the columns of that type that are not a Face. :float, :integer and
456
- # :complex are the kinds, not the C type names cast reads them as.
455
+ # picks the columns of that type that are not a Face.
457
456
  private def columns_of_kind(kind, verb)
458
457
  matches =
459
458
  case kind
@@ -489,7 +488,7 @@ class CAFrame
489
488
  return false if col.face? || col.data_type != :object
490
489
  found = false
491
490
  col.each do |v|
492
- next if UNDEF.equal?(v)
491
+ next if UNDEF.equal?(v) || v.nil?
493
492
  return false unless v.is_a?(String)
494
493
  found = true
495
494
  end
@@ -499,7 +498,7 @@ class CAFrame
499
498
  # Column projection (memo §13.2): a view-frame holding the named columns as
500
499
  # aliases (zero-copy, sharing storage with the parent frame). Distinct from
501
500
  # +df[...]+, which escapes columns to raw CArrays, and from +filter+, which
502
- # selects rows. +select+ takes no block — row conditions go through +filter+
501
+ # selects rows. +select+ takes no block (it raises) — row conditions go through +filter+
503
502
  # (old carray-dataframe fused the two into +select(cols) { cond }+; here they
504
503
  # are orthogonal and compose by chaining: +df.select(...).filter { ... }+).
505
504
  # Each argument is a name, a Range of names (the columns from one to the
@@ -508,7 +507,8 @@ class CAFrame
508
507
  #
509
508
  # df.select("station", "tmax".."rain")
510
509
  # df.select(/^t/)
511
- def select(*names)
510
+ def select(*names, &block)
511
+ refuse_column_verb_block("select") if block
512
512
  raise ArgumentError, "select requires at least one column name" if names.empty?
513
513
  cols = {}
514
514
  names_selected(names, "select").each do |key|
@@ -518,6 +518,14 @@ class CAFrame
518
518
  rebuild(cols)
519
519
  end
520
520
 
521
+ # select and drop name columns; a block (the Enumerable reading, rows for
522
+ # which it is true) is refused rather than dropped.
523
+ private def refuse_column_verb_block(verb)
524
+ raise ArgumentError,
525
+ "#{verb} takes column names, not a block; to pick rows by a " \
526
+ "condition, use filter { |f| ... }"
527
+ end
528
+
521
529
  # Keep the rows where a boolean selector is true. The selector is given
522
530
  # directly (+df.filter(df["temp"] > 0)+), or built by a block that receives
523
531
  # the frame (+df.filter { |f| f["temp"] > 0 }+), from +f["col"]+ /
@@ -578,7 +586,7 @@ class CAFrame
578
586
  # at, picked as +select+ picks them.
579
587
  # @return [CAFrame]
580
588
  # @raise [KeyError] for a name that is no column.
581
- def drop_masked (*names)
589
+ def drop_masked(*names)
582
590
  keys = names.empty? ? @columns.keys : names_selected(names, "drop_masked")
583
591
  holes = CArray.boolean(@nrow).fill(false)
584
592
  keys.each do |key|
@@ -650,8 +658,8 @@ class CAFrame
650
658
  verdicts[key] = verdict
651
659
  end
652
660
  # The verdicts are a table about the rows, not a part of this one, so the
653
- # frame's attributes are not carried.
654
- CAFrame.new(verdicts, axis_name: @axis_name, index: @index)
661
+ # frame's attributes are not carried and the index is its own.
662
+ CAFrame.new(verdicts, axis_name: @axis_name, index: @index&.copy)
655
663
  end
656
664
 
657
665
  # A new frame with a column moved to the index and the row axis named
@@ -707,6 +715,7 @@ class CAFrame
707
715
  # The first +n+ rows as a positional view-frame (memo §11.3). +n+ larger
708
716
  # than +nrow+ yields the whole frame; +n+ of 0 yields an empty frame.
709
717
  def head(n = 5)
718
+ raise TypeError, "head: the count is an Integer (got #{n.inspect})" unless n.is_a?(Integer)
710
719
  raise ArgumentError, "head count must be non-negative (got #{n})" if n < 0
711
720
  row_span(0, [n, @nrow].min)
712
721
  end
@@ -714,6 +723,7 @@ class CAFrame
714
723
  # The last +n+ rows as a positional view-frame (memo §11.3). +n+ larger
715
724
  # than +nrow+ yields the whole frame; +n+ of 0 yields an empty frame.
716
725
  def tail(n = 5)
726
+ raise TypeError, "tail: the count is an Integer (got #{n.inspect})" unless n.is_a?(Integer)
717
727
  raise ArgumentError, "tail count must be non-negative (got #{n})" if n < 0
718
728
  row_span(@nrow - [n, @nrow].min, @nrow)
719
729
  end
@@ -728,6 +738,28 @@ class CAFrame
728
738
  # a row Hash and stays that way: zero matches raise KeyError, and duplicate
729
739
  # labels raise (go through +filter { |f| f.index.eq(label) }+ for the
730
740
  # multi-row, frame-returning path). Positional access is +df[i]+.
741
+ # A number as the index compares it without rounding: a whole float beside
742
+ # integers is an integer, and an integer beside floats that no float holds
743
+ # is no label there (a float32 index holds fewer integers than a float64
744
+ # one).
745
+ private def exact_label(label)
746
+ return label if @index.face?
747
+ if @index.integer? && label.is_a?(Float) && label.finite? && label == label.floor
748
+ label.to_i
749
+ elsif @index.float? && label.is_a?(Integer) && !index_float_holds?(label)
750
+ Float::NAN
751
+ else
752
+ label
753
+ end
754
+ end
755
+
756
+ # Whether the index's float type holds +n+ exactly.
757
+ private def index_float_holds?(n)
758
+ f = n.to_f
759
+ f = [f].pack("f").unpack1("f") if @index.data_type == CA_FLOAT32
760
+ f.finite? && f.to_i == n
761
+ end
762
+
731
763
  def at(label)
732
764
  raise ArgumentError, "at requires an index (set one with set_index)" unless @index
733
765
  # An index may hold a masked cell -- an outer join and align both build one
@@ -751,8 +783,8 @@ class CAFrame
751
783
  "at: the index is #{@index.data_type}, so the label must be a number " \
752
784
  "(got #{label.inspect}); convert it first, e.g. at(Float(s)) or at(Integer(s))"
753
785
  end
754
- nan = label.is_a?(Float) && label.nan?
755
- hit = nan ? @index.is_in([label]) : @index.eq(label)
786
+ nan = label.is_a?(Numeric) && label != label
787
+ hit = nan ? @index.is_in([label]) : @index.eq(exact_label(label))
756
788
  pos = hit.where
757
789
  case pos.elements
758
790
  when 0
@@ -782,7 +814,7 @@ class CAFrame
782
814
  #
783
815
  # @param other [Object]
784
816
  # @return [Boolean]
785
- def == (other)
817
+ def ==(other)
786
818
  return true if equal?(other)
787
819
  return false unless other.is_a?(CAFrame)
788
820
  return false unless column_names == other.column_names && @axis_name == other.axis_name
@@ -797,7 +829,7 @@ class CAFrame
797
829
 
798
830
  # A key value as an error message shows it: a String quoted, an element of
799
831
  # a Face (a time, say) as it reads.
800
- def self.key_text (value)
832
+ def self.key_text(value)
801
833
  return value.inspect if value.is_a?(String) || value.is_a?(Numeric) || value.nil?
802
834
  return value.to_s if value.class.name.to_s.end_with?("::Element")
803
835
  return value.inspect
@@ -1182,7 +1214,7 @@ class CAFrame
1182
1214
  # an index, the spliced-in frame must have one too (its rows need labels).
1183
1215
  private def splice_index(other, lo, hi)
1184
1216
  return nil unless @index
1185
- if other.nrow > 0 && other.index.nil?
1217
+ if other.index.nil?
1186
1218
  raise ArgumentError,
1187
1219
  "splice frame needs an index because the target frame has one"
1188
1220
  end
@@ -1207,9 +1239,9 @@ class CAFrame
1207
1239
  end
1208
1240
 
1209
1241
  # Resolve a contiguous span [lo, hi) for splice, reusing the row-axis indexer
1210
- # classifier (CArray.scan_index) so negatives, exclusive ends,
1211
- # ArithmeticSequence and the [start, count(, step)] array forms parse exactly
1212
- # as they do for a column key. Only a POINT (single row) or a step-1 BLOCK
1242
+ # classifier (CArray.scan_index) so negatives, exclusive ends and
1243
+ # ArithmeticSequence parse exactly as they do for a column key. Only a
1244
+ # POINT (single row) or a step-1 BLOCK
1213
1245
  # (contiguous slice) has a span to replace; a strided or scattered selector
1214
1246
  # raises.
1215
1247
  #
@@ -1225,10 +1257,10 @@ class CAFrame
1225
1257
 
1226
1258
  info = CArray.scan_index([@nrow], [selector])
1227
1259
  case info.type
1228
- when CA_REG_POINT
1260
+ when :point
1229
1261
  i = info.index[0]
1230
1262
  [i, i + 1]
1231
- when CA_REG_BLOCK
1263
+ when :block
1232
1264
  start, count, step = info.index[0]
1233
1265
  unless step == 1
1234
1266
  raise ArgumentError,
@@ -1237,12 +1269,14 @@ class CAFrame
1237
1269
  [start, start + count]
1238
1270
  else
1239
1271
  raise ArgumentError,
1240
- "splice (df[...] = frame) needs a contiguous slice (Range, Integer, " \
1241
- "or [start, count]); got #{selector.class}"
1272
+ "splice (df[...] = frame) needs a contiguous slice (Range or " \
1273
+ "Integer); got #{selector.class}"
1242
1274
  end
1243
1275
  end
1244
1276
 
1245
1277
  private def select_rows(selector)
1278
+ # With no column and no index, nothing else bound-checks the selector.
1279
+ selected_row_mask(selector) if @columns.empty? && @index.nil?
1246
1280
  cols = {}
1247
1281
  @columns.each do |name, col|
1248
1282
  cols[name] = col[selector, *([nil] * (col.ndim - 1))]
@@ -1264,6 +1298,12 @@ class CAFrame
1264
1298
  raise KeyError, "#{lead}no column #{key.inspect}"
1265
1299
  end
1266
1300
 
1301
+ # The column a verb is given by name, the verb leading the refusal of a
1302
+ # name that is no column.
1303
+ private def named_column(key, verb)
1304
+ @columns.fetch(key) { refuse_missing_column(key, verb) }
1305
+ end
1306
+
1267
1307
  # filter takes no keyword. keep_masked:, which it once took, is named
1268
1308
  # with where its work went: the selector settles an undetermined row.
1269
1309
  def self.refuse_filter_keywords(options, verb)
@@ -1330,14 +1370,16 @@ class CAFrame
1330
1370
  # percentile(p, *names): the percentage comes first. A name there is the
1331
1371
  # order of median's arguments carried over, said so; a percentage out of
1332
1372
  # range is refused by the core here, before any column is asked whether
1333
- # it has a percentile.
1373
+ # it has a percentile. A CScalar is one percentage, as the core reads it;
1374
+ # the percentage is returned as a Numeric.
1334
1375
  def self.check_percentage(p)
1335
- unless p.is_a?(Numeric)
1376
+ unless p.is_a?(Numeric) || p.is_a?(CScalar)
1336
1377
  raise ArgumentError,
1337
1378
  "percentile: give the percentage first, then the column names " \
1338
1379
  "(got #{p.inspect}; percentile(90, \"x\"))"
1339
1380
  end
1340
1381
  CArray.float64(1).percentile(p)
1382
+ p.is_a?(CScalar) ? p[0] : p
1341
1383
  end
1342
1384
  private_class_method :check_percentage
1343
1385