Skip to content

to_netcdf can fail due to usage of CategoricalDtype #112

@smithara

Description

@smithara

Current versions of (pandas/xarray?) are now causing a failure in xarray.Dataset.to_netcdf with the datasets generated by viresclient where "Spacecraft" is stored as a pandas.Categorical, where this didn't happen before.

For example:

import pandas as pd
import xarray as xr

ds = xr.Dataset(
    data_vars={
        "x": ("t", pd.Categorical(["A", "B", "B", "A"], categories=["A", "B"]))
    }
)
ds.to_netcdf("test.h5")

fails with:

TypeError: Cannot interpret 'CategoricalDtype(categories=['A', 'B'], ordered=False, categories_dtype=object)' as a data type

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