BUG: fix usage of na_sentinel with sort=True in factorize() by jorisvandenbossche · Pull Request #25592 · pandas-dev/pandas (original) (raw)
@jorisvandenbossche do you find this clearer? Personally, I find these dummy variables just for flow control a bit confusing (you have to verify that things are eventually set somewhere). With the way things are written, it's clear that each of the three branches has a uniques
and labels
, and it's clear how things are achieved.
If we're really concerned about repeating the call to safe_sort, you can make a closer with the values
get_uniques_labels = lambda: safe_sort(uniques, labels, na_sentinel, assume_unique=True)`
and call the lambda, but again, that's just unnecessary indirection IMO.
In this case I think just do whatever.