Skip to content

iris.pandas.as_data_frame cannot handle scalar cubes #6419

Open
@schlunma

Description

@schlunma

🐛 Bug Report

Running iris.pandas.as_data_frame on a scalar cube (e.g., Cube(1.0)) currently fails with a ValueError.

How To Reproduce

Steps to reproduce the behaviour:

import iris
import iris.pandas
from iris.cube import Cube

iris.FUTURE.pandas_ndim = True

cube = Cube(1.0)

df = iris.pandas.as_data_frame(cube)

gives

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 11
      7 iris.FUTURE.pandas_ndim = True
      9 cube = Cube(1.0)
---> 11 df = iris.pandas.as_data_frame(cube)

File ~/micromamba/envs/esm/lib/python3.12/site-packages/iris/pandas.py:846, in as_data_frame(cube, copy, add_aux_coords, add_cell_measures, add_ancillary_variables)
    843     data = data.astype("f").filled(np.nan)
    845 # Extract dim coord information: separate lists for dim names and dim values
--> 846 coord_names, coords = _make_dim_coord_list(cube)
    847 # Make base DataFrame
    848 index = pd.MultiIndex.from_product(coords, names=coord_names)

ValueError: not enough values to unpack (expected 2, got 0)

Expected behaviour

No error. The resulting data frame could look like this:

       unknown
0      1.0

For comparison, the output of a 1D cube (Cube([1.0]) looks like this currently:

          unknown
dim0         
0         1.0

Environment

  • OS & Version: Linux
  • Iris Version: 3.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Status

    🆕 Candidate

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions