Add join method to StringExpression#9459
Conversation
| :class:`.StringExpression` | ||
| Joined string expression. | ||
| """ | ||
| if collection.dtype.element_type != tstr: |
There was a problem hiding this comment.
should we convert elements to string automatically if of another type? Would let you do hl.str(',').join([1,2,3])
There was a problem hiding this comment.
not necessary though, up to you.
There was a problem hiding this comment.
I started out having this call hl.delimit, but added the element type check to make it behave more like Python's string.join, which raises a TypeError if passed an iterable with non-string elements.
There was a problem hiding this comment.
I think checking first and then calling delimit() would replicate Python functionality?
There was a problem hiding this comment.
Regardless of whether we do the element type check or not, we should still call hl.delimit afterwards as opposed to mkString, to minimize how often we leak java implementation details.
There was a problem hiding this comment.
Ah, I misunderstood the comment and thought you were suggesting replace the entire implementation with a call to delimit.
There was a problem hiding this comment.
After thinking about it some more, I like the type check as a guard rail. Automatic type conversion would be useful for things like joining an array of numbers. On the other hand, it would also let you accidentally join an array of structs when it's more likely you wanted to join from one of the struct's fields.
|
thanks Nick! |
* Add join method to StringExpression * Use hl.delimit
Requested in #9188.
This is similar to hl.delimit. However, unlike hl.delimit, this throws a TypeError if a collection with a non-string element type is provided. This matches the behavior of Python's str.join.