Skip to content

Series / DataFrame view method not implemented. #8439

Closed

Description

@ocqco

When attempting to convert a column from one dtype to another using astype, there is a FutureWarning raised by Dask and Pandas regarding the move to using view.

Pandas suggests replacing the astype method with view, however view appears not to be implemented in dask.dataframe.core.

This is the FutureWarning from Pandas:

FutureWarning: casting datetime64[ns] values to int64 with .astype(...) is deprecated and will raise in a future version. Use .view(...) instead.
df['TIMESTAMP_astype'] = df['TIMESTAMP'].astype('int64')

Setup:

import pandas as pd
import dask.dataframe as dd

data = {
    'TIMESTAMP': [
        '2021-11-27 00:05:02.175274',
        '2021-11-27 00:05:05.205596',
        '2021-11-27 00:05:29.212572',
        '2021-11-27 00:05:25.708343',
        '2021-11-27 00:05:47.714958',
    ]
}

df = pd.DataFrame(data)
df['TIMESTAMP'] = pd.to_datetime(df['TIMESTAMP'])

ddf = dd.from_pandas(df, npartitions=1)
ddf['TIMESTAMP'] = dd.to_datetime(ddf['TIMESTAMP'])

Pandas code:

df['TIMESTAMP_astype'] = df['TIMESTAMP'].astype('int64')  # works - throws FutureWarning
df['TIMESTAMP_view'] = df['TIMESTAMP'].view('int64')  # works

assert (df['TIMESTAMP_astype'] == df['TIMESTAMP_view']).all()  # True

Dask code:

ddf['TIMESTAMP_astype'] = ddf['TIMESTAMP'].astype('int64')  # works - throws FutureWarning
ddf['TIMESTAMP_view'] = ddf['TIMESTAMP'].view('int64')  # error - below

Not implemented view in dask.dataframe.core:

AttributeError: 'Series' object has no attribute 'view'

Activity

  1. changed the title [-]DataFrame view method not implemented.[/-] [+]Series / DataFrame view method not implemented.[/+] on Dec 1, 2021
  2. ian-r-rose commented on Dec 1, 2021

    @ian-r-rose
    Collaborator

    Thanks for raising this @ocqco . It looks like this deprecation was added in pandas 1.3.0. I also see some heartache downstream related to this in holoviews: holoviz/holoviews#5146.

    I don't think it would be hugely difficult to add a view method to dask.dataframe.

  3. added
    good second issue
    on Dec 1, 2021
  4. jorisvandenbossche commented on Jan 18, 2022

    @jorisvandenbossche
    Member

    Small note that we are undoing this deprecation, see pandas-dev/pandas#45449 (pandas-dev/pandas#45034).

    That aside, it can of course still be useful to add a .view() method (but it should certainly make it less critical)

  5. ian-r-rose commented on Jan 18, 2022

    @ian-r-rose
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dataframegood second issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions