-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
MAINT: More informative TypeError for IndexEngine.get_loc #12414
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
Are either of the following necessary for this PR:
|
I don't believe this ever becomes an external exception |
But the issue that I'm closing showed an example where the Exception was thrown |
so this is right so add a test that asserts the contents of the error message it's s type error because the indexer is not the correct type to select the level |
cbf859d
to
6104a7d
Compare
Added a test, and the test passes on Travis. Should be good to merge if there is nothing else. |
@@ -2590,3 +2590,19 @@ def test_head_tail(self): | |||
empty_df = DataFrame() | |||
assert_frame_equal(empty_df.tail(), empty_df) | |||
assert_frame_equal(empty_df.head(), empty_df) | |||
|
|||
def test_type_error_multiindex(self): | |||
df = pd.DataFrame(columns=['i', 'c', 'x', 'y'], |
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.
add the issue number 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.
Done.
6104a7d
to
dde5da3
Compare
Not really sure why Python 3.4 is failing, as the failing test case has no relation to what I changed. I'm going to rebase onto |
dde5da3
to
9c49efd
Compare
str(dg[:, 0]) | ||
|
||
# Neither of the following commands should | ||
# throw a TypeError because they are valid |
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.
you don't need to put these asserts around here, just run the actual commands. if they raise the tests will fail; this just obfuscuates tings. best is actually to test the results
e.g.
result = dg.loc[:, (slice(None), 0)]
expected = ....
assert_.....
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.
Done.
149921b
to
0dac883
Compare
Tests are passing, so this should be good to merge if there is nothing else. |
can you add a whatsnew note (you can put in bug fixes is fine). ping when pushed. |
018.0 is ok |
0dac883
to
0062307
Compare
Sorry, as soon as I posted the question, I saw you had already added it to the |
0062307
to
5bf5c5b
Compare
@@ -1117,3 +1117,4 @@ Bug Fixes | |||
- Bug in ``DataFrame.apply`` in which reduction was not being prevented for cases in which ``dtype`` was not a numpy dtype (:issue:`12244`) | |||
- Bug when initializing categorical series with a scalar value. (:issue:`12336`) | |||
- Bug when specifying a UTC ``DatetimeIndex`` by setting ``utc=True`` in ``.to_datetime`` (:issue:11934) | |||
- Bug in ``IndexEngine.get_loc`` in which an empty ``TypeError`` was being thrown instead of one with an error message (:issue:12218) |
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.
just say that you added a meaningful error message when multi-axis indexing with an invalid value.
these whatsnotes are for the average user. Those who want/need more detail can simply click on the issue itself. But for a quick glance, just need to highlite terms that most users would know.
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.
Ah, okay. Good to know.
00b9545
to
831c3a1
Compare
labels=[[0, 1], [0, 0]], | ||
names=[None, 'c']) | ||
values = np.array([[1, 2], [3, 4]], dtype=np.int64) | ||
index = Index(data=[0, 1], dtype='int64', name='i') |
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.
oh I see you the index has a name, ok then.
Still construct like this
index = Index(range(2), name='i')
it automatically is int64
you can just construct
expected = DataFrame([[1, 2], [3, 4], columns=columns, dtype='int64')
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 need to intermix numpy arrays at all here. Its just confusing to a reader.
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.
Sure thing. Done.
831c3a1
to
5a66b7d
Compare
Could you cancel some of my duplicate, older builds? I see no reason for them to run given all of the updating I have done. Thanks! |
done, do you know any way to configure that on Travis? (e.g. it builds pull-requests, but I want force pushes to cancel anything but the last one). |
Unfortunately not. See here. |
actually I think this will work as the ref commit is now gone. (if you force push on the same branch) |
I'm not entirely sure I follow what you mean since I do force pushes all time with my PR's in |
what I mean is that if you force push, then when Travis tries to build it is fails (but is grey so doesn't count) and doesn't build the previous commit (but instead builds your new one) |
On a separate note, is there a |
Regarding Travis: that should work I suppose, but I haven't seen that work consistently in practice, at least not in this library. IDK if there's a way to guarantee Travis can't find the old ref. |
@gfyoung where is this list defined? yes easy to add to Travis |
Oh, I meant : does such a mailing list exist? |
@gfyoung could create one, what I meant was does @jorisvandenbossche @TomAugspurger would this be useful? |
@gfyoung can you make a separate issue about this. (and include that pointer) |
thanks! |
Title is self-explanatory. Closes #12218.