Skip to content

BUG? Can construct constant Series and DataFrame, but not Panel or Panel4D #8285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seth-p opened this issue Sep 16, 2014 · 1 comment · Fixed by #9640
Closed

BUG? Can construct constant Series and DataFrame, but not Panel or Panel4D #8285

seth-p opened this issue Sep 16, 2014 · 1 comment · Fixed by #9640
Milestone

Comments

@seth-p
Copy link
Contributor

seth-p commented Sep 16, 2014

Is it accidental that the Series and DataFrame constructors accept a single number for data, but the Panel and Panel4D constructors do not?

In [182]: from pandas import Series, DataFrame, Panel, Panel4D

In [183]: Series(1., index=range(2))
Out[183]:
0    1
1    1
dtype: float64

In [184]: DataFrame(1., index=range(2), columns=range(2))
Out[184]:
   0  1
0  1  1
1  1  1

In [185]: Panel(1., items=range(2), major_axis=range(2), minor_axis=range(2))
---------------------------------------------------------------------------
PandasError                               Traceback (most recent call last)
<ipython-input-185-89f6618b848f> in <module>()
----> 1 Panel(1., items=range(2), major_axis=range(2), minor_axis=range(2))

C:\Python34\lib\site-packages\pandas\core\panel.py in __init__(self, data, items, major_axis, minor_axis, copy, dtype)
    133                  copy=False, dtype=None):
    134         self._init_data(data=data, items=items, major_axis=major_axis,
--> 135                         minor_axis=minor_axis, copy=copy, dtype=dtype)
    136
    137     def _init_data(self, data, copy, dtype, **kwargs):

C:\Python34\lib\site-packages\pandas\core\panel.py in _init_data(self, data, copy, dtype, **kwargs)
    161             dtype = None
    162         else:  # pragma: no cover
--> 163             raise PandasError('Panel constructor not properly called!')
    164
    165         NDFrame.__init__(self, mgr, axes=axes, copy=copy, dtype=dtype)

PandasError: Panel constructor not properly called!

In [186]: Panel4D(1., labels=range(2), items=range(2), major_axis=range(2), minor_axis=range(2))
---------------------------------------------------------------------------
PandasError                               Traceback (most recent call last)
<ipython-input-187-8f22d9107a3e> in <module>()
----> 1 Panel4D(1., labels=range(2), items=range(2), major_axis=range(2), minor_axis=range(2))

C:\Python34\lib\site-packages\pandas\core\panel4d.py in panel4d_init(self, data, labels, items, major_axis, minor_axis, copy, dtype)
     37     self._init_data(data=data, labels=labels, items=items,
     38                     major_axis=major_axis, minor_axis=minor_axis,
---> 39                     copy=copy, dtype=dtype)
     40
     41 Panel4D.__init__ = panel4d_init

C:\Python34\lib\site-packages\pandas\core\panel.py in _init_data(self, data, copy, dtype, **kwargs)
    161             dtype = None
    162         else:  # pragma: no cover
--> 163             raise PandasError('Panel constructor not properly called!')
    164
    165         NDFrame.__init__(self, mgr, axes=axes, copy=copy, dtype=dtype)

PandasError: Panel constructor not properly called!
@jreback
Copy link
Contributor

jreback commented Sep 16, 2014

Panel and subclasses use the same constructors (so a panel and Panel4d should behave similarly)

but this should work with a scalar

@jreback jreback added this to the 0.15.1 milestone Sep 16, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 13, 2015
jreback added a commit that referenced this issue Mar 14, 2015
support constructing Panel or Panel4D with scalar data, fixes #8285
yarikoptic added a commit to neurodebian/pandas that referenced this issue Jul 2, 2015
Version 0.16.0

* tag 'v0.16.0': (24 commits)
  RLS: v0.16.0 final
  DOC: update release notes, v0.16.0.txt
  DOC: further clean-up whatsnew file
  DOC: add v0.16.1.txt starter template
  TST: remove old tests that just skipped
  Added itertools.groupby equivalent example.
  COMPAT: windows dtype fix on series formatting tests
  DOC: io.rst fixups
  DOC: example of pandas to R transfer of DataFrame using HDF5 file
  DOC: grammar fixes, add conda install to README
  DOC: don't create backlinks in the whatsnew section
  FIX: Series text representation
  PERF: optimize memory usage for to_hdf
  API: spurious setting_with_copy warning (GH8730)
  DOC: organize stringmethods whatsnew
  CI: don't remove python-dateutil at end of install
  COMPAT: dtype conform on windows for panel construct from a scalar
  COMPAT: odd arrays can be correctly ordered in newer versions of numpy
  support constructing Panel or Panel4D with scalar data, fixes pandas-dev#8285
  DOC: Fix heading level for assign
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants