Skip to content

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

Closed
wants to merge 25 commits into from
Closed

DEPR: Deprecate use of un-supported numpy dt64/td64 dtype for pandas.array #53439

wants to merge 25 commits into from

Conversation

rmhowe425
Copy link
Contributor

@rmhowe425 rmhowe425 commented May 29, 2023

@rmhowe425 rmhowe425 marked this pull request as draft May 29, 2023 16:33
@rmhowe425 rmhowe425 marked this pull request as ready for review May 29, 2023 19:24
@rmhowe425
Copy link
Contributor Author

@jbrockmendel Would you be able to take a look at this PR and let me know if its good to go?

@@ -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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this change?

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

@rmhowe425 rmhowe425 Jun 3, 2023

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?

@jbrockmendel
Copy link
Member

Oh, i see. #53058 isnt about deprecating all dt64/td64 dtypes, just the unsupported units. we support s, ms, us, ns.

@mroeschke mroeschke added the Deprecate Functionality to remove in pandas label Jun 1, 2023
@@ -203,6 +218,8 @@
],
)
def test_array(data, dtype, expected):
with open("/home/richard/Desktop/file.txt", "a+") as fil:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldnt be needed

@jbrockmendel
Copy link
Member

In pd.array, at the end where we have checks for is_supported_dtype, do an 'else' statement and issue a deprecation warning

@rmhowe425
Copy link
Contributor Author

rmhowe425 commented Jun 3, 2023

@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?

image

@rmhowe425 rmhowe425 requested a review from jbrockmendel June 11, 2023 19:42
@rmhowe425
Copy link
Contributor Author

@jbrockmendel PR is ready for inspection. Failing test does not appear to be related to PR

@rmhowe425
Copy link
Contributor Author

@jbrockmendel PR is ready for inspection

@@ -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`)
Copy link
Member

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

@@ -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":
Copy link
Member

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")

f"dtype={dtype_var} is not supported. Supported resolutions are 's', 'ms', "
"'us', and 'ns'"
)
with pytest.raises(TypeError, match=re.escape(msg)):
Copy link
Member

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

@rmhowe425
Copy link
Contributor Author

@jbrockmendel Fixed PR based on recommendations and pinging on green!

@rmhowe425 rmhowe425 requested a review from jbrockmendel June 16, 2023 03:22
@@ -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`)
Copy link
Member

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"

@rmhowe425 rmhowe425 requested a review from jbrockmendel June 21, 2023 19:17
@rmhowe425
Copy link
Contributor Author

@jbrockmendel PR is ready for inspection.

Failing tests are unrelated to PR. Doctest and code checks are passing

@rmhowe425 rmhowe425 closed this by deleting the head repository Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: pd.array convert unsupported dt64/td64 to supported?
3 participants