Changing the default ak.flatten axis from axis=1 to axis=None: any complaints? #845
Replies: 1 comment 2 replies
-
Hey @jpivarski, this is a great summary of where things stand. I think that it would be worth overloading Concerning |
Beta Was this translation helpful? Give feedback.
-
ak.flatten flattens one level of list depth by default:
This is what users of functional programming languages (LISPs, Scala, Spark) would expect:
but it has come up more than once as a surprise. Users in our community expect
ak.flatten
to "completely flatten," which is an option, but not the default one:In part, this may be because other dimension-reducing operations have
axis=None
as a default, such as the reducers:Actually, I would have had the default axis for reducers be
axis=-1
, but NumPy forced the default to beaxis=None
. (I don't seeak.flatten
as being "similar to"ak.sum
et al.)If there's a strong consensus—i.e. a lot of people "+1"ing this or otherwise chiming in—then we can change the default. That will be rough, since the name "
ak.flatten
" is a good one that I don't want to change and a switch in default without renaming the function is going to break somebody's code, possibly in subtle ways (i.e. wrong answer, rather than an error message like "this function doesn't exist anymore, use the new name with the new default").Here's how it could be done, if there's a groundswell of support for it: I can immediately make the default argument a dummy object that, if detected, will raise a warning saying, "`ak.flatten default axis is changing from 1 to None in version 1.4.0 (2021-08-01); please specify an explicit axis for now" and then change the default at that time. This is referring to the scheduled semi-major releases in which breaking changes are allowed. Anyone who upgrades Awkward Array between now and August will get the message and adjust. Anyone who doesn't—people who have already upgraded to Awkward 1.x but do not upgrade again in this 3.5 month window—won't see the message and risk getting an error due to a default behavior changing under them.
As an alternative, we could leave
ak.flatten
as it is and introduceak.ravel
(a NEP 18 overload of np.ravel), which is justak.flatten
withaxis=None
. That doesn't help people who are incorrectly guessing thatak.flatten
completely flattens—it's a different function name to remember—but it seems appropriate to me because "np.ravel
" is the NumPy word for "complete flatten," and it doesn't conflict with the usage of "flatten" in functional programming.So, let me know what you think! This thread was prompted by #832, and @masonproffitt and @agoose77, if you want to point others to this to avoid letting this thread die in obscurity, please do so.
Beta Was this translation helpful? Give feedback.
All reactions