daru icon indicating copy to clipboard operation
daru copied to clipboard

[API] Vector: adding new values

Open zverok opened this issue 8 years ago • 5 comments

Here is the list of what feels right for me, ready to discuss!

I assume that Daru::Vector is a bit like Ruby's Array, and a bit like Hash. So:

  • like Array:
    • push(index, value) to add index-value pair to the end of vector (and << as a synonym);
    • (not sure) << value -- pushes value + auto-calculated index (by vector.index.last.succ, for ex.);
    • insert_after(lookup_index, new_index, new_value) (and insert_before for symmetry);
  • like Hash:
    • vector[:non_existent_index] = value should work, not raise IndexError (unless there is REALLY good reason for current behavior);
    • (not sure) merge(index: value) (and merge!, of course).

zverok avatar May 27 '16 10:05 zverok

Well Vector/DataFrame don't function exactly like Array and are not designed to be expanded. It would involve a lot of unnecessary overhead like checking for missing value, updating missing value, size and indexing data structures internally and in general consuming more memory and time than is necessary.

You'd rather just use an Array, expand it as much as you want and then create a Vector from it for performing computations.

v0dro avatar May 27 '16 16:05 v0dro

Which once again return us to https://github.com/v0dro/daru/issues/137 ;)

What I think about (looking at real R code using dataframes heavily, which I now can access at work) is all-in-all Vector and DataFrame as just a new containers (which I personally would like to have as popular as an Array/Hash), and they should be as intuitive in that role as possible. And if daru's user wants to create dataframe with 100 rows, then add another 100 by parsing some data, and then another 100 using some API -- there is no really good (e.g. conceptual) reason why he/she can't "just do it".

Those containers aren't immutable, they aren't even immutable in some of directions (like "you can compute new columns, but can't add new rows"), so, this limitation (it is not easy/intuitive to ad new row to DF/new value to Vector) seems pretty artificial.

zverok avatar May 28 '16 18:05 zverok

Hmmmm you have a point, but I'd like to discuss this and #137 further before we come to any decisions. It can have far reaching implications for daru as a whole.

v0dro avatar May 28 '16 19:05 v0dro

vector[:non_existent_index] = value should work, not raise IndexError (unless there is REALLY good reason for current behavior);

I'm about to work on Daru::Vector#[]= and was wondering if this feature should be supported. For Data frames, this feature is supported.

lokeshh avatar May 29 '16 17:05 lokeshh

(Adding to milestone, needs reconsidering in a common flow of cleanup)

zverok avatar Oct 08 '17 21:10 zverok