-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
API: how to check for "logical" equality of dtypes? #60305
Comments
And maybe an additional question is how to propagate that notion of "exact equality" vs "logical equality" into methods like |
One idea is to make IMHO, let |
Something like |
I think these should compare as equal if they are logically equivalent; otherwise we are back to the issue of exposing the implementation detail to end users. So I think the reverse of being proposed is what we should have. By default, equality comparisons use the logical semantics, and if you wanted a more granular physical comparison you should use a dedicated function. I think we have a prior art for that already when considering |
@WillAyd that would create a change of behavior. See this example: >>> s = pd.Series([1,2,3], dtype="Int64")
>>> s2 = pd.Series([1,2,3])
>>> s
0 1
1 2
2 3
dtype: Int64
>>> s2
0 1
1 2
2 3
dtype: int64
>>> s.dtype == s2.dtype
False So you're proposing that |
In the long run yes...although we definitely need to be careful about the steps that we take to get there. I'm also coming from the perspective that we've discussed in PDEP-13, where |
There seems to be a concern about changing the behavior of equality checks, as it could affect users who rely on the current exact equality checks.
as @WillAyd mentions this is exposing the implementation detail to end users. So could it be considered reasonable to argue that this is a bug and a change would be a bugfix not a change in behavior for just this dtype in isolation which is still currently considered experimental? |
Yea that's an interesting point that @simonjayhawkins brings up. Do we think there's a huge risk to changing that behavior for strings today? |
Assume you have a series, which has a certain dtype. In the case that this dtype is an instance of potentially multiple variants of a logical dtype (for example, string backed by python or backed by pyarrow), how do you check for the "logical" equality of such dtypes?
For checking the logical equality for one series, you have the option to compare it with the generic string alias (which will return True for any variant of it) or checking the dtype with
isinstance
or someis_..._dtype
(although we have deprecated some of those). Using string dtype as the example:When you want to check if two serieses have the same dtype, the
==
will check for exact equality (in the string dtype example, the below can evaluate to False even if both are a StringDtype, but have a different storage):But so how to check this logical equality for two dtypes? In the example, how to know that both dtypes are representing the same logical dtype (i.e. both a StringDtype instance), without necessarily wanting to check the exact type (i.e. the user doesn't necessarily know it are string dtypes, just want to check if they are logically the same)
Do we want some other API here that is a bit more user friendly? (just brainstorming, something like
dtype1.is_same_type(dtype2)
, or a function, ..)This is important in the discussion around logical dtypes (#58455), but so it is already an issue for the new string dtype as well in pandas 3.0
cc @WillAyd @Dr-Irv @jbrockmendel (tagging some people that were most active in the logical dtypes discussion)
The text was updated successfully, but these errors were encountered: