You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspired by #983 and CoffeaTeam/coffea#750, we need to take another look at ak.firsts and ak.singletons to make sure that they behave sensibly for all array types (e.g. that high-coverage suite of layouts copy-pasted from one v2 test to another) and add an axis parameter if it does not exist.
What firsts is supposed to do is: turn an array of var * X into an array of option[X] (of the same length) by returning the first item of each non-empty list and None for empty lists. ak.firsts(array) is like array[:, 0] except that it does not raise an exception if there are any empty lists. This has a natural extension to any axis and should work for lists buried within anything.
What singletons is supposed to do is: turn an array of option[X] into an array of var * X where each None maps to [] and each instance x of X maps to [x]. This can also be done at any axis.
The two functions are inverses of each other, exact inverses if firsts acts on lists of lengths 0 and 1 exclusively. These are the two ways of representing missing data: with a missingness token (None, which Awkward Array favors in all operations except this one) and with lists of length 0 and 1. (Option type is a monoid; I think only functional languages take this seriously.)
These two functions are pretty high in the count of number of uses across GitHub:
The only thing to do for next-release is to put warnings into the functions saying that the semantics will likely change. With the warning, this issue doesn't close, but the next-release label can be removed.
Inspired by #983 and CoffeaTeam/coffea#750, we need to take another look at
ak.firsts
andak.singletons
to make sure that they behave sensibly for all array types (e.g. that high-coverage suite of layouts copy-pasted from one v2 test to another) and add anaxis
parameter if it does not exist.What
firsts
is supposed to do is: turn an array ofvar * X
into an array ofoption[X]
(of the same length) by returning the first item of each non-empty list andNone
for empty lists.ak.firsts(array)
is likearray[:, 0]
except that it does not raise an exception if there are any empty lists. This has a natural extension to anyaxis
and should work for lists buried within anything.What
singletons
is supposed to do is: turn an array ofoption[X]
into an array ofvar * X
where eachNone
maps to[]
and each instancex
ofX
maps to[x]
. This can also be done at anyaxis
.The two functions are inverses of each other, exact inverses if
firsts
acts on lists of lengths 0 and 1 exclusively. These are the two ways of representing missing data: with a missingness token (None
, which Awkward Array favors in all operations except this one) and with lists of length 0 and 1. (Option type is a monoid; I think only functional languages take this seriously.)These two functions are pretty high in the count of number of uses across GitHub:
and in the count of number of repos in which they were seen across GitHub:
The text was updated successfully, but these errors were encountered: