-
Notifications
You must be signed in to change notification settings - Fork 15
Map values according to a dict #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I'm currently -1 on this. The mental model I see here is that we can take a dict and construct a Matrix from it, then use that to update another Matrix. In that case, it would be assign, not apply. Looking at your example was not at all obvious what was going on. And that is the worry I have with each new addition. They seem simple, but unless someone knows all the corners and shortcuts, it makes it harder to read someone else's code. I'm open to being convinced, but these are my initial thoughts on the proposal. |
Round(s) of convincing (and likely improvements) is expected and appreciated.
I have no idea what you mean by this. The equivalent recipe is: C = Matrix(A.dtype, A.nrows, A.ncols)
C(A.S) << default
for k, v in d.items()
C(A == k) << v This is just like I don't doubt use cases for this will arise (supposing we get more users), and alternatives to perform this are pretty ugly and most likely slower. So, I think this is worth exploring, but we can keep it on the back-burner and wait until we have conventions for showing examples in docstrings. We've been pushing core features forward faster than we can document them (with good reason), but we need documentation to catch up, and we should be in the habit of requiring sufficient documentation for PRs like this. Possible enhancements:
|
Okay, I think the natural API for this is: def applymap(self, mapping, default=None): where
I think the keys should be coerced to the dtype of the parent object dtype, and values coerced to the output object dtype. This will let us handle UDTs and awkward dtypes like Edit: changed name from |
Closes #246.
A.apply({1: 10, 2: 20}, 999)
Heh, I know this isn't high priority (at all!), but it is oh-so-fun and was quick to do. I think the function we jit with numba is pretty competitive.
I doubt this handles UDTs, and we could probably be a bit smarter with dtypes in general.