doc/Vector.md in red_amber-0.1.4 vs doc/Vector.md in red_amber-0.1.5

- old
+ new

@@ -31,22 +31,22 @@ ### `size`, `length`, `n_rows`, `nrow` ### `type` -### `data_type` +### `boolean?`, `numeric?`, `string?`, `temporal?` +### `type_class` + ### [ ] `each` (not impremented yet) ### [ ] `chunked?` (not impremented yet) ### [ ] `n_chunks` (not impremented yet) ### [ ] `each_chunk` (not impremented yet) -### `tally` - ### `n_nils`, `n_nans` - `n_nulls` is an alias of `n_nils` ### `inspect(limit: 80)` @@ -124,24 +124,27 @@ | ✓ `abs` | | ✓ | | | | |[ ]`acos` | | [ ] | | | | |[ ]`asin` | | [ ] | | | | | ✓ `atan` | | ✓ | | | | | ✓ `bit_wise_not`| | (✓) | | |integer only| -|[ ]`ceil` | | ✓ | | | | +| ✓ `ceil` | | ✓ | | | | | ✓ `cos` | | ✓ | | | | -|[ ]`floor` | | ✓ | | | | +| ✓`fill_nil_backward`| ✓ | ✓ | ✓ | | | +| ✓`fill_nil_forward` | ✓ | ✓ | ✓ | | | +| ✓ `floor` | | ✓ | | | | | ✓ `invert` | ✓ | | | |`!`, alias `not`| |[ ]`ln` | | [ ] | | | | |[ ]`log10` | | [ ] | | | | |[ ]`log1p` | | [ ] | | | | |[ ]`log2` | | [ ] | | | | -|[ ]`round` | | [ ] | |[ ] Round| | -|[ ]`round_to_multiple`| | [ ] | |[ ] RoundToMultiple| | +| ✓ `round` | | ✓ | | ✓ Round (:mode, :n_digits)| | +| ✓ `round_to_multiple`| | ✓ | | ✓ RoundToMultiple :mode, :multiple| multiple must be an Arrow::Scalar| | ✓ `sign` | | ✓ | | | | | ✓ `sin` | | ✓ | | | | +| ✓`sort_indexes`| ✓ | ✓ | ✓ |:order|alias `sort_indices`| | ✓ `tan` | | ✓ | | | | -|[ ]`trunc` | | ✓ | | | | +| ✓ `trunc` | | ✓ | | | | ### Binary element-wise: `vector.func(vector) => vector` ![binary element-wise](doc/image/../../image/vector/binary_element_wise.png) @@ -178,18 +181,137 @@ | ✓ `subtract` | | ✓ | | | `-` | | ✓ `shift_left` | | (✓) | | |`<<`, integer only| | ✓ `shift_right` | | (✓) | | |`>>`, integer only| | ✓ `xor` | ✓ | | | | `^` | +### `uniq` + + Returns a new array with distinct elements. + (Not impremented functions) -### [ ] sort, sort_index + +### `tally` and `value_counts` + + Compute counts of unique elements and return a Hash. + + It returns almost same result as Ruby's tally. These methods consider NaNs are same. + + ```ruby + array = [0.0/0, Float::NAN] + array.tally #=> {NaN=>1, NaN=>1} + + vector = RedAmber::Vector.new(array) + vector.tally #=> {NaN=>2} + vector.value_counts #=> {NaN=>2} + ``` + +### `sort_indexes`, `sort_indices`, `array_sort_indices` + +### [ ] `sort`, `sort_by` ### [ ] argmin, argmax ### [ ] (array functions) ### [ ] (strings functions) ### [ ] (temporal functions) ### [ ] (conditional functions) ### [ ] (index functions) ### [ ] (other functions) ## Coerce (not impremented) -## Updating (not impremented) +## Update vector's value +### `replace_with(booleans, replacements)` => vector + +- Accepts Vector, Array, Arrow::Array for booleans and replacements. + - Replacements can accept scalar +- Booleans specifies the position of replacement in true. +- Replacements specifies the vaues to be replaced. + - The number of true in booleans must be equal to the length of replacement + +```ruby +vector = RedAmber::Vector.new([1, 2, 3]) +booleans = [true, false, true] +replacemants = [4, 5] +vector.replace_with(booleans, replacemants) +# => +#<RedAmber::Vector(:uint8, size=3):0x000000000001ee10> +[4, 2, 5] +``` + +- Scalar value in replacements can be broadcasted. + +```ruby +replacemant = 0 +vector.replace_with(booleans, replacement) +# => +#<RedAmber::Vector(:uint8, size=3):0x000000000001ee10> +[0, 2, 0] +``` + +- Returned data type is automatically up-casted by replacement. + +```ruby +replacement = 1.0 +vector.replace_with(booleans, replacement) +# => +#<RedAmber::Vector(:double, size=3):0x0000000000025d78> +[1.0, 2.0, 1.0] +``` + +- Position of nil in booleans is replaced with nil. + +```ruby +booleans = [true, false, nil] +replacemant = -1 +vec.replace_with(booleans, replacement) +=> +#<RedAmber::Vector(:int8, size=3):0x00000000000304d0> +[-1, 2, nil] +``` + +- Replacemants can have nil in it. + +```ruby +booleans = [true, false, true] +replacemants = [nil] +vec.replace_with(booleans, replacemants) +=> +#<RedAmber::Vector(:int8, size=3):0x00000000000304d0> +[nil, 2, nil] +``` + +- If no replacemants specified, it is same as to specify nil. + +```ruby +booleans = [true, false, true] +vec.replace_with(booleans) +=> +#<RedAmber::Vector(:int8, size=3):0x00000000000304d0> +[nil, 2, nil] +``` + +- An example to replace 'NA' to nil. + +```ruby +vector = RedAmber::Vector.new(['A', 'B', 'NA']) +vector.replace_with(vector == 'NA', nil) +# => +#<RedAmber::Vector(:string, size=3):0x000000000000f8ac> +["A", "B", nil] +``` + +### `fill_nil_forward`, `fill_nil_backward` => vector + +Propagate the last valid observation forward (or backward). +Or preserve nil if all previous values are nil or at the end. + +```ruby +integer = RedAmber::Vector.new([0, 1, nil, 3, nil]) +integer.fill_nil_forward +# => +#<RedAmber::Vector(:uint8, size=5):0x000000000000f960> +[0, 1, 1, 3, 3] + +integer.fill_nil_backward +# => +#<RedAmber::Vector(:uint8, size=5):0x000000000000f974> +[0, 1, 3, 3, nil] +```