-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Series.__repr__ is broken for SparseDtype("datetime64[ns]") #35843
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
Comments
A few possible fixes:
\1) is certainly the easiest change; 3) might be nice to get in place longer term |
Option 2 seems to be along the lines of @jorisvandenbossche suggestion of potentially treating sparse dtypes as "just sparse" (a similar question came up in regard to problems with considering sparse categorical to be categorical). You would presumably still have SparseDtype.subtype.kind == "M" if it's needed. |
moved off 1.1.2 milestone (scheduled for this week) as no PRs to fix in the pipeline |
moved off 1.1.3 milestone (overdue) as no PRs to fix in the pipeline |
moved off 1.1.4 milestone (scheduled for release tomorrow) as no PRs to fix in the pipeline |
we want to avoid undoing the performance gains, so ideally we don't want to revert #33400 option 2 does not sound like the correct solution for a regression fix, as SparseDtype.kind was also 'M' on 1.0.5, and changing that may introduce other regressions, but agree that we should perhaps move in that direction on master. on 1.0.5 both However, on 1.1.4
on 1.0.5
so it appears that only is_datetime64tz_dtype needs to be changed. |
so we could just remove
from since this pattern (for EA checks) is also added for |
In the formatting, rightly or wrongly, the SparseArray is converted to a DatetimeIndex and this is where the failure occurs. so the underlying issue here is that creating an Index from a on master
on 1.0.5
if we don't want to revert parts of #33400, we could special case for SparseArray. I'm not a fan of special casing, but special casing was used to fix Series construction in #35838, a regression also caused by #33400 If we want to do similar here to fix the Index construction case, we could patch as follows... diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py
index ce70f929c..67b57851a 100644
--- a/pandas/core/arrays/datetimes.py
+++ b/pandas/core/arrays/datetimes.py
@@ -38,6 +38,7 @@ from pandas.core.dtypes.common import (
is_float_dtype,
is_object_dtype,
is_period_dtype,
+ is_sparse,
is_string_dtype,
is_timedelta64_dtype,
pandas_dtype,
@@ -1921,7 +1922,6 @@ def sequence_to_dt64ns(
------
TypeError : PeriodDType data is passed
"""
-
inferred_freq = None
dtype = _validate_dt64_dtype(dtype)
@@ -1956,7 +1956,11 @@ def sequence_to_dt64ns(
data, copy = maybe_convert_dtype(data, copy)
data_dtype = getattr(data, "dtype", None)
- if is_object_dtype(data_dtype) or is_string_dtype(data_dtype):
+ if (
+ is_object_dtype(data_dtype)
+ or is_string_dtype(data_dtype)
+ or is_sparse(data_dtype)
+ ):
# TODO: We do not have tests specific to string-dtypes,
# also complex or categorical or other extension
copy = False |
instead of checking .kind, could directly check |
you've given more thought than i have to what is proper solution vs what constitutes crack-papering. If reverting #33400 is necessary, i'll choose correctness over performance every time. |
A proper solution is probably not suitable for regression fixes. IIUC the proper solution has been discussed elsewhere, #35843 (comment) |
yeah let's just do what @simonjayhawkins proposed for expediency we need to release if want to fix differently for 1.2 ok with that |
by 'papering over the cracks', i was referring to the PRs adding the special casing for SparseArray.
is that revert #33400 (and maybe #35838 too) or merge and backport #38332 to just fix the known issue. |
#34986 related |
Regression due to 1fa0635 :
xref #35762
The text was updated successfully, but these errors were encountered: