Skip to content

UnboundLocalError when setting data to a Panel: "local variable 'mat' referenced before assignment" #452

@andreas-h

Description

@andreas-h

Hi,

the following code produces a UnboundLocalError when executed with pandas 0.6.0 / Python 2.7:

import datetime
import pandas
timeidx = pandas.DateRange(start=datetime.datetime(2009,1,1),
                       end=datetime.datetime(2009,12,31),
                       offset=pandas.datetools.MonthEnd())
lons_coarse = np.linspace(-177.5, 177.5, 72)
lats_coarse = np.linspace(-87.5, 87.5, 36)
P = pandas.Panel(items=timeidx, major_axis=lons_coarse, minor_axis=lats_coarse)
P[datetime.datetime(2009,2,28)] = np.random.randn(72*36).reshape((72,36))

Maybe this is to be expected, but it's definitely not intuitive. Since both P[datetime.datetime(2009,2,28)] and np.random.randn(72*36).reshape((72,36)) have shape (72,36), I would expect this to work.

Until it does, what would be the way to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions