wesm/pandas — Issue #452: UnboundLocalError when setting data to a Panel: "local variable 'mat' referenced before assignment"
Author: andreas-h
Created: 2011-12-06 15:32:31+00:00
State: open

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?