Skip to content

Slowness when cftime is installed #3000

Closed
@0x0L

Description

@0x0L

With cftime installed

import numpy as np
import pandas as pd
import xarray as xr

da = xr.DataArray(np.random.randn(5000, 500))
df = da.to_pandas()

# with pandas
%time df_stacked = df.stack()
# Wall time: 48.3 ms
%time df_unstacked = df_stacked.unstack()
# Wall time: 368 ms

# with xarray
%time da_stacked = da.stack(stacked_dim=('dim_0', 'dim_1'))
# Wall time: 1.03 s
%time da_unstacked = da_stacked.unstack('stacked_dim')
# Wall time: 78.2 ms

prun points to CFTimeIndex(index) in _maybe_cast_to_cftimeindex

The behaviour is also incorrect for empty indexes:

da[:0].stack(dim=['dim_0', 'dim_1']).dim.to_index()
# CFTimeIndex([], dtype='object', name='dim')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions