Skip to content

BUG: Let CategoricalIndex take CategoricalDtype as dtype argument #18116

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
Nov 5, 2017

Conversation

topper-123
Copy link
Contributor

This PR allows CategoricalIndex to take CategoricalDtype as its dtype argument, see #18109 for details.

@jreback
Copy link
Contributor

jreback commented Nov 4, 2017

lgtm. can you add a release note, 0.21.1 is good.

@jreback jreback added Bug Categorical Categorical Data Type labels Nov 4, 2017
@topper-123 topper-123 force-pushed the CategoricalIndex_dtype branch 2 times, most recently from 350e0be to 6d48a08 Compare November 4, 2017 22:03
tm.assert_index_equal(result, expected, exact=True)

# error to combine categories or ordered and dtype keywords args
with pytest.raises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

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

We generally try to avoid using pytest.raises because tm.assert_raises_regex is more effective. What's the error message that you get when calling the constructor as such?

Copy link
Contributor

Choose a reason for hiding this comment

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

pytest.raises is ok, sure if you really want to check the message then use assert_raises_regex, i don't think its a big deal here

Copy link
Member

Choose a reason for hiding this comment

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

Well, that's why I'm asking.

Copy link
Contributor Author

@topper-123 topper-123 Nov 4, 2017

Choose a reason for hiding this comment

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

The message is "Cannot specify both dtype and categories or ordered." in both cases.

FYI, pytest can now take a parameter match which does the same thing (i.e. with pytest.raises(ValueError, match="Cannot specify both `dtype` and `categories` or `ordered`." ):). This is a new feature added in pytest 3.1, so its very new. Pandas doesn't seem to have a minimum specified version of pytest, but it's reasonable to be able to test pandas with version < 3.1 of pytest, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually we do have a min version of 3.1

Copy link
Contributor

Choose a reason for hiding this comment

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

it’s in our travis install, the requirements files and i believe the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, found it in contributing.rst: "The earliest supported pytest version is 3.1.0.".

It would make sene to have it in install.rst also as there is a section there on running the test suite.

Copy link
Contributor

Choose a reason for hiding this comment

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

the section in install should simply point to contributing
we don’t wants things in more than one place

Copy link
Member

Choose a reason for hiding this comment

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

@jreback : Do you think it would make sense to no longer tm.assert_raises_regex if we have pytest.raises in our toolbox now (unrelated to PR)?

Copy link
Contributor

Choose a reason for hiding this comment

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

i don’t see a lot of benefit of changing
but could be persuaded

@topper-123 topper-123 force-pushed the CategoricalIndex_dtype branch from 6d48a08 to 016f08c Compare November 5, 2017 00:31
@codecov
Copy link

codecov bot commented Nov 5, 2017

Codecov Report

Merging #18116 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18116      +/-   ##
==========================================
+ Coverage   91.25%   91.26%   +<.01%     
==========================================
  Files         163      163              
  Lines       50124    50124              
==========================================
+ Hits        45742    45745       +3     
+ Misses       4382     4379       -3
Flag Coverage Δ
#multiple 89.07% <100%> (+0.02%) ⬆️
#single 40.32% <100%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/category.py 97.46% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️
pandas/plotting/_converter.py 65.2% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8388a47...016f08c. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 5, 2017

Codecov Report

Merging #18116 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18116      +/-   ##
==========================================
+ Coverage   91.25%   91.26%   +<.01%     
==========================================
  Files         163      163              
  Lines       50124    50124              
==========================================
+ Hits        45742    45745       +3     
+ Misses       4382     4379       -3
Flag Coverage Δ
#multiple 89.07% <100%> (+0.02%) ⬆️
#single 40.32% <100%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/category.py 97.46% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️
pandas/plotting/_converter.py 65.2% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8388a47...016f08c. Read the comment docs.

@topper-123
Copy link
Contributor Author

Pinging at green @jreback.

@jreback jreback added this to the 0.21.1 milestone Nov 5, 2017
@jreback jreback merged commit 58c2f09 into pandas-dev:master Nov 5, 2017
@jreback
Copy link
Contributor

jreback commented Nov 5, 2017

thanks!

@topper-123 topper-123 deleted the CategoricalIndex_dtype branch November 5, 2017 11:26
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Dec 8, 2017
TomAugspurger pushed a commit that referenced this pull request Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting CategoricalIndex with dtype=CategoricalDtype doesn't work (v0.21)
3 participants