-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series.reshape to own shape raises TypeError #4659
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
Conversation
|
# GH 2719 | ||
a = Series([1, 2, 3, 4]) | ||
self.assertRaises(TypeError, a.reshape, 2, 2) | ||
# GH 4554 | ||
assert_almost_equal(a.reshape(a.shape), a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use assert_series_equal
.
How comes you deleted the test above? Is there a reason not just do the same test there (i.e. make it assert_series_equal(x.reshape(len(x),), x)
? Does this work with name (assert_series_equal will test name too)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh..but the reshape actually returns an ndarray
here (which IMO) is a bit odd, but its for numpy compat;
@goyodiaz add an assertion about the type as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback If this is all for numpy compat, why can't we just do arbitrary reshapes? I may be asking a silly question here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, on an exactly equal reshape you get back the series, anything else you get a numpy array (assume its equal sized), but the ndim has changed, e.g. (2,2) for a len(4) series is ok, but by definition you get a numpy array; I think mainly for compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean the test above will fail? (i.e. not raise)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, because it compares a with a (both are series), which is correct (though this should be)
assert_series_equal
though, @goyodiaz. I know the API is a little screwy, but ndarrays permit ndim changes, while pandas does not, so not much choice, any better ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback Sorry, I meant this one: self.assertRaises(TypeError, a.reshape, 2, 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that looks a.reshape((2,2))
should just return an ndarray I think
@hayd Point taken, I'll try to minimize changes to existing tests. Back to the code, I realized that more work needed to be done. There are currently two assertions in
This is the bug I reported.
So I have changed the test according to this and rewrite Sorry I got git to make a mess of my fork's history. I have been told this can be cleaned up but I am not used to git so I would appreciate some advice. |
To cleanup your branch run the following git remote add upstream https://www.github.com/pydata/pandas.git
git fetch upstream
# will need to fix merge conflicts here
git rebase upstream/master
# pops up window, change 'pick' to 'squash' to combine commits
git rebase -i upstream/master |
fyi ... you can also replace "pick" with "fixup" to remove the commit messages that squash leaves hanging around. this is great for those commits that fix typos/syntax errors, etc. |
@cpcloud anything else? |
@goyodiaz Needs to be rebased. |
Sorry, not sure what I'm expected to do. I rebased my changes on top of upstream again. |
probably a merge conflict with release notes .... gotta do it again |
travis is passing so that's good ... just resolve the merge conflict and BAM! it'll get merged :) |
One of the travis build jobs failed but I don't understand how it can be related to my patch. |
It's not crazy that a change to reshape might have caused an issue, though it does seem unrelated. @jreback - thoughts on the failing build? |
nope...that's a ocassional test failure that have never been able to nail down (travis once in a while fails it, but never can reproduce locally)....I think this is ready to merge, any objections? |
@goyodiaz thank you! |
closes #4554
I just fixed the call to ndarray.reshape with order as a positional argument, which is wrong. Please note that I had to remove a test.