Repository navigation
Conversation
|
@jorisvandenbossche from pandas might be interested |
|
It should be noted that in my thoughts, I have ignored |
de343ba to
4fd7380
Compare
5f59dd1 to
db3781c
Compare
|
@seberg I just caught up on the numpy mailing list thread on this topic, am reading through the hackmd page you wrote. Which of these is the preferred place for discussion? Mainly I'm thinking of how pandas could use this. |
|
Here is fine, there is also a PR at numpy, which is a bit more up to date than the HackMD in places, but maybe the HackMD is better and I should just keep them more or less in sync. You can certainly comment inside the hackmd , although that is a bit easy to miss, and thus slow maybe. Email will work (me or mailing list), but maybe github PR/issue is a bit nicer. I suppose we could also just open a discussion issue on NumPy. I could also schedule another video conference meeting soon. (It will have to be within about the next week, after that I will be unavailable for a month). |
|
Oh, we also have weekly community calls from BIDS which will happen in about 1.5 hours. We could extend/talk a bit more at the end (I expect it will not be super long today, but since these are so big discussions would prefer to do it at the end when everyone can excuse themselves). EDIT: Meeting info https://hackmd.io/76o-IxCjQX2mOXO_wwkcpg?both |
|
Sounds good. Will stick with here for now. Some thoughts/questions on what would make this really useful on my end (likely overlap with what TomAugspurger has said):
|
Tricky question. I think it is a pretty even thing probably, however, the plan now is to use
This is a pretty big issue, that I have not given much thought. The problem with these things is that the buffer interface (and C) do not define these types. We can tag on additional information, and I think we should probably make it easy for cython to ask for the "C loop function of the ufunc", but that still is going to be annoying. It is an interesting issue, I am tempted to claim it is a bit orthogonal, but that does not help much. I do not mind (allowing) tagging on information to dtypes if that makes life easier. But I am not sure what that would need to be. |
Totally fair, declaring things orthogonal is the best way to keep big things like this manageable. A few more thoughts after reading through the hackmd document:
|
|
Thanks for taking the time and reading it!
Can you point me to this? Casting is tricky with flexible dtypes, but even if it is not perfect, I am currently fairly happy about the state. Although, I am considering adding fast-path methods for the To be honest, I do not remember what Jeff Reback told me about it, but I cannot actually find how casting is currently defined in pandas?
Thanks, will be useful to expand on these things a bit, before the end...
This is a global
Yeah, we need that. There is a wide range of use cases, from just creating something like quaternions (which is practically a specialized structured array) to completely new dtypes in C that also need scalars. It would be nice to make (common) things like quaternions super simple. I think even currently, for someone who knows the python C-API well, the current dtype API is a bit limited. Mind you, I actually do not think it is super difficult, but there is not much docs to get in easy and that is assuming you are one of the few people who feels at easy in writing python types in C from scratch...
While I would somewhat prefer to limit at least modification of the metaclass for starters. The plan is to give users full flexibility to define their DType (classes) and instances as they like. Which would mean that even if NumPy dtypes are missing some fields of your ExtensionDTypes, you could still make them full fledged NumPy dtypes. I.e. in this case, probably mainly tag on The extension dtype class will be a And the instance of that will be a One main difference may be that I currently did not have any aspiration for a |
The function I was thinking of is maybe_promote which does upcasting slightly differently from numpy (Note: the function is a mess and subject of several current PRS). can_cast checks are probably most analogous to Block._can_hold_element. ATM ExtensionArray/ExtensionDtype don't handle this directly, but probably should. The other thing that comes to mind is lib.infer_dtype, though that is less about casting than inference.
This is a global registry so that pandas is aware of any user-defined ExtensionDTypes, e.g. registering IntervalDtype. (This may not actually be necessary now that I think of it. Going to open an issue about that...) ExtensionArray (EA) does not have a well-defined notion of a scalar type, so there is no type->dtype mapping. ExtensionDtype does have a _construct_array_type method to get the corresponding ExtensionArray subclass. The docs for EA authors are here. Definitely let me know if things are unclear.
Yah, I'm not a big fan of that one either. So it goes. |
|
I have to spend a bit more time with the pandas extension types maybe. Ijust tried to try out The thing I would like to see is simply how pint currently handles that I suppose there should also be a method to achieve One main difference, as far as I understand it, is that I want to make sure everything is defined as slots on the dtype and completely separate from the container, which is something pandas does not currently do/achieve? However, that does not mean that pandas cannot keep supporting it, I think. There is another thing in that it would be awesome to tag on dtype specific (u)functions to arrays. It seems pandas has (weird?!) hooks to do so. But I think that is again a whole new story/NEP. |
Sorry if I was unclear, AFAICT pint-pandas is still under construction. I've been following it intermittently in the hopes that it would come together. I may end up implementing a units EA for pandas myself, but would rather wait and avoid re-implementing lots of pint-based stuff that they have already thought through.
If I were to write this, I would do something like: (I'm not a huge fan of the _add_arithmetic_ops/_add_comparison_ops pattern, but so it goes). You can see something like this happening in pandas.core.arrays.integer.IntegerArray. I haven't looked at all, but assume that pint implements something akin to I actually think a lot of EA subclasses (not just units) can be defined with a similar pattern. A large majority of extant EA subclasses are thin wrappers around np.ndarrays.
slots as in
Can you expand on this? Some of our EA subclasses implement |
|
Thanks, that is very helpful. I see the existence of Yes, everything should be on defined either:
Dispatching to the " (I did not think too much about the syntax, this is not how it is supposed to look like in the end). You would also be able to register resolver functions, since your Unit DType will want to see what numpy makes of
Oh, I just meant |
Just to clarify on the "have to" part of this: the example I gave used ExtensionOpsMixin, which is what has the _create_arithmetic_method classmethod. That is useful primarily in the (very common) case where the arithmetic method in question is a template-able wrapper around an np.ndarray method. For DatetimeArray/TimedeltaArray/PeriodArray, we define the arithmetic methods directly in pandas.core.arrays.datetimelike.DatetimelikeArrayMixin. So to be clear: if you wanted to write an EA and use some completely different pattern to define these methods, none of that would violate the EA interface.
This looks vaguely familiar since I'm looked through the numpy code a few times for datetime-parsing-related stuff, but I've never really gotten a grasp on it. Is there some bite-sized piece of the numpy code that I could/should read to be able to discuss this more competently?
Now I'm curious about how numpy defines arithmetic/comparison operations. Consider
For calling |
Yes, but I think it is all pretty similar in our world. Your interface is very similar to
This pattern (or anything like this) does not really exist right now. What we have is
Those are all
Of course the |
The first is to keep some errors from the overload machinery identical. The second one is because flags may be set by the user after the ufunc creation (It seems this only happens in a single test). The second one may need a bit of thought...
Intermittently there was a bug around how scalars interact with GetArrayParamsFromObject, this is not fixed and clearer, but might warrent new tests since only a single test fro pad failed...
To achive this, add a parameter to return NULL for DType/descr during discovery.
The hole that I do not define multistep casting right now still exists though.
and removing the profane comment :)
New OO->? loops were added (maybe by accident), they are harmless but need the disambiguity needs to be resolved in this branch.
0c84f86 to
6b218b1
Compare
03d8be5 to
fc2518b
Compare
90918b4 to
ff13409
Compare
commit 9c833bed5879d77e625556260690c349de18b433 Author: Thomas Li <[email protected]> Date: Wed Nov 17 16:21:27 2021 -0800 Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Update cibw_test_command.sh commit 4bd12df Author: Thomas Li <[email protected]> Date: Mon Nov 15 17:28:47 2021 -0800 # This is a combination of 14 commits. # This is the 1st commit message: Add Windows config to GHA # This is the commit message #2: update script [wheel build] # This is the commit message #3: typo [wheel build] # This is the commit message #4: fix typo? [wheel build] # This is the commit message #5: fix linux builds? [wheel build] # This is the commit message #6: typo [wheel build] # This is the commit message #7: add license and pin to windows 2016 # This is the commit message #8: skip tests [wheel build] # This is the commit message #9: pin to windows 2019 instead [wheel build] # This is the commit message #10: try to find out the error on windows [wheel build] # This is the commit message #11: maybe fix? [wheel build] # This is the commit message #12: maybe fix? [wheel build] # This is the commit message #13: fix? [wheel build] # This is the commit message #14: cleanup [wheel build]
EDIT: Current state will largely run.
np.ma.maskedis a small issue in calculation. Complex scalars have incorrect promotion rules (not value based). Public exposure of new features is a main issue right now (and general cleanup). Reductions, etc. are not yet covered by the new ufunc machinery.I decided to create this PR within my own branch to have a place to put in case someone asks. At this time this is largely hacky, but demonstrates a few things (with more thing being added). This is the start of an implementation of the proposal in: https://hackmd.io/kxuh15QGSjueEKft5SaMug
Things that work:
type(np.dtype("float64"))and the other types are now subclasses ofnp.dtype(with some basic info, but no features exposed to python really).type(np.dtype)andtype(type(np.float64))is now aDTypeMetaclass, this means that:type(np.float64)has DType specific methods (classmethods ofnp.dtype("float64")so to say)CanCastTypeTo(no value based casting)PromoteTypes(no value based promotion)GetDTypeTransferFunction(only partially, some API decisions need to be done, although they do not fix a final API necessarily).