-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: Deprecate use of un-supported numpy dt64/td64 dtype for pandas.array #53439
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
Conversation
@jbrockmendel Would you be able to take a look at this PR and let me know if its good to go? |
doc/source/reference/arrays.rst
Outdated
@@ -22,8 +22,6 @@ can be found at :ref:`basics.dtypes`. | |||
=================== ========================== ============================= ============================= | |||
Kind of Data pandas Data Type Scalar Array | |||
=================== ========================== ============================= ============================= | |||
TZ-aware datetime :class:`DatetimeTZDtype` :class:`Timestamp` :ref:`api.arrays.datetime` | |||
Timedeltas (none) :class:`Timedelta` :ref:`api.arrays.timedelta` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel Maybe I didn't completely understand #53058. Are we not removing all dt.td64 dtypes?
I removed the above, as it was part of the dt/td64 documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said here #53439 (comment), we aren't deprecating all dt64/td64, just the un-supported resolutions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel Ah okay understood!
Looking at the implementation, it looks like the changes for this PR need to be made either in _ensure_nanosecond_dtype()
in cast.py, or in the implementation for is_supported_unit()
in dtypes.pyi.
Seeing that is_supported_unit()
in dtypes.pyi is an interface, I'm assuming that there is a definition for this function for pd.array, but I don't see it. Would you be able to shed some light on how this interface method is being used?
Oh, i see. #53058 isnt about deprecating all dt64/td64 dtypes, just the unsupported units. we support s, ms, us, ns. |
pandas/tests/arrays/test_array.py
Outdated
@@ -203,6 +218,8 @@ | |||
], | |||
) | |||
def test_array(data, dtype, expected): | |||
with open("/home/richard/Desktop/file.txt", "a+") as fil: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt be needed
In pd.array, at the end where we have checks for is_supported_dtype, do an 'else' statement and issue a deprecation warning |
@jbrockmendel I should add a deprecation warning rather than a TypeError? I was thinking that we wanted to raise an error rather than a deprecation warning? Is the image below what you're looking for? If we use an else statement I think that we'll be throwing a deprecation warning for other supported dtypes before we hit the return statement at the bottom. I had my td64/dt64 check up top. Are we okay with me adding an elif statement at the bottom and checking for the unsupported types? |
@jbrockmendel PR is ready for inspection. Failing test does not appear to be related to PR |
@jbrockmendel PR is ready for inspection |
doc/source/whatsnew/v2.1.0.rst
Outdated
@@ -291,6 +291,7 @@ Deprecations | |||
- Deprecated positional indexing on :class:`Series` with :meth:`Series.__getitem__` and :meth:`Series.__setitem__`, in a future version ``ser[item]`` will *always* interpret ``item`` as a label, not a position (:issue:`50617`) | |||
- Deprecated the "method" and "limit" keywords on :meth:`Series.fillna`, :meth:`DataFrame.fillna`, :meth:`SeriesGroupBy.fillna`, :meth:`DataFrameGroupBy.fillna`, and :meth:`Resampler.fillna`, use ``obj.bfill()`` or ``obj.ffill()`` instead (:issue:`53394`) | |||
- Deprecated the ``method`` and ``limit`` keywords in :meth:`DataFrame.replace` and :meth:`Series.replace` (:issue:`33302`) | |||
- Deprecated the use of dt64/td64 dtypes with :func:`pandas.array` (:issue:`53439`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only un-supported. we supports "s", "ms", "us", "ns" resolutions
pandas/core/construction.py
Outdated
@@ -379,6 +378,9 @@ def array( | |||
): | |||
return TimedeltaArray._from_sequence(data, dtype=dtype, copy=copy) | |||
|
|||
elif isinstance(dtype, np.dtype) and dtype.kind in "mM": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib.is_np_dtype(dtype, "mM")
pandas/tests/arrays/test_array.py
Outdated
f"dtype={dtype_var} is not supported. Supported resolutions are 's', 'ms', " | ||
"'us', and 'ns'" | ||
) | ||
with pytest.raises(TypeError, match=re.escape(msg)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to issue a FutureWarning saying it will raise in the future (or cast to closest-supported-unit), not raise
@jbrockmendel Fixed PR based on recommendations and pinging on green! |
doc/source/whatsnew/v2.1.0.rst
Outdated
@@ -291,6 +291,7 @@ Deprecations | |||
- Deprecated positional indexing on :class:`Series` with :meth:`Series.__getitem__` and :meth:`Series.__setitem__`, in a future version ``ser[item]`` will *always* interpret ``item`` as a label, not a position (:issue:`50617`) | |||
- Deprecated the "method" and "limit" keywords on :meth:`Series.fillna`, :meth:`DataFrame.fillna`, :meth:`SeriesGroupBy.fillna`, :meth:`DataFrameGroupBy.fillna`, and :meth:`Resampler.fillna`, use ``obj.bfill()`` or ``obj.ffill()`` instead (:issue:`53394`) | |||
- Deprecated the ``method`` and ``limit`` keywords in :meth:`DataFrame.replace` and :meth:`Series.replace` (:issue:`33302`) | |||
- Deprecated the use of hour and minute dt64/td64 resolutions with :func:`pandas.array`. Supported resolutions are: "s", "ms", "us", "ns" resolutions (:issue:`53439`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are others besides hour/minute, say "non-supported". similarly please write out "datetime64 and timedelta64"
@jbrockmendel PR is ready for inspection. Failing tests are unrelated to PR. Doctest and code checks are passing |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.