Skip to content
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

FutureWarning: casting datetime64[ns] values to int64 with .astype(...) is deprecated #5146

Closed
hoxbro opened this issue Nov 20, 2021 · 8 comments · Fixed by #5157
Closed

Comments

@hoxbro
Copy link
Member

hoxbro commented Nov 20, 2021

ALL software version info

numpy.__version__ = '1.20.3'
holoviews.__version__ = '1.14.6'

Description of expected behavior and the observed behavior

Casting datetime64[ns] values to int64 with .astype(...) is deprecated

Complete, minimal, self-contained example code that reproduces the issue

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({
    "time": pd.date_range("2020", "2021" ,100),
    "data": 100 * [1],
})

df.hvplot.line("time", "data", datashade=True)

Stack traceback and/or browser JavaScript console output

C:\Users\shh\miniconda3\envs\clean_holoviz\lib\site-packages\holoviews\operation\datashader.py:428: FutureWarning: casting datetime64[ns] values to int64 with .astype(...) is deprecated and will raise in a future version. Use .view(...) instead.
  df[d.name] = vals.astype('int64')
@jbednar
Copy link
Member

jbednar commented Nov 21, 2021

Sounds like a straightforward PR to make from the error message, but then if so I'm not sure why it's deprecated and not simply done automatically any more, so maybe there is more to it than that.

@philippjfr
Copy link
Member

Yeah, I don't really understand the reasoning behind this change tbh. We rely on this a lot all over the place iirc.

@hoxbro
Copy link
Member Author

hoxbro commented Nov 22, 2021

The warning was added here: pandas-dev/pandas#38544

@jbednar
Copy link
Member

jbednar commented Nov 27, 2021

Oh my; that link leads to a lot of discussion: pandas-dev/pandas#22384 (comment)

I'm not at all sure that the issue has been resolved one way or another, i.e. whether the deprecation will be implemented or reverted, so I'd be inclined to wait on this until such a change is released definitively in pandas.

@hoxbro
Copy link
Member Author

hoxbro commented Nov 27, 2021

The change will also not be as straightforward as the error message for Holoviews, which also can handle Dask DataFrames and Series, which doesn't have a view attribute. So a function to convert would look something like this:

def convert_to_int64(x):
    if pd.isna(x).any():
        raise ValueError("Cannot convert NaN/NaT values to integer")

    if dd and isinstance(x, (dd.DataFrame, dd.Series)):  # Dask does not have view
        return x.astype("int64")
    else:
        return x.view("int64")

@jbednar
Copy link
Member

jbednar commented Nov 27, 2021

Ugh! Yes, let's not make this change until we are certain we will need it.

@jorisvandenbossche
Copy link

FYI, the deprecation warning has been reverted

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants