Skip to content

support constructing Panel or Panel4D with scalar data, fixes #8285 #9640

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

Merged
merged 1 commit into from
Mar 14, 2015

Conversation

mortada
Copy link
Contributor

@mortada mortada commented Mar 13, 2015

this should fix #8285

@@ -888,6 +888,21 @@ def test_constructor(self):
wp = Panel(vals, copy=True)
self.assertIsNot(wp.values, vals)

# test when scalar data is used to construct a Panel
# if dtype is not passed, it should be inferred
value_and_dtype = [(1, int), (3.14, float), ('foo', np.object_)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue number here

@jreback
Copy link
Contributor

jreback commented Mar 13, 2015

ok, pls add a release note (this can go in 0.16.0)

dtype, data = _infer_dtype_from_scalar(data)
values = np.empty([len(x) for x in passed_axes], dtype=dtype)
values.fill(data)
mgr = self._init_matrix(values, passed_axes, dtype=dtype, copy=copy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to make copy= False before you init the matrix (so it doesn't copy it again). Copy is irrelevant with a scalar anyhow.

@mortada mortada force-pushed the panel_init_scalar branch from 09be167 to cc8bf97 Compare March 13, 2015 19:56
@mortada
Copy link
Contributor Author

mortada commented Mar 13, 2015

@jreback thanks it's fixed now

jreback added a commit that referenced this pull request Mar 14, 2015
support constructing Panel or Panel4D with scalar data, fixes #8285
@jreback jreback merged commit dc79fd7 into pandas-dev:master Mar 14, 2015
@jreback
Copy link
Contributor

jreback commented Mar 14, 2015

@mortada thanks!

@mortada mortada deleted the panel_init_scalar branch April 29, 2015 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG? Can construct constant Series and DataFrame, but not Panel or Panel4D
2 participants