Skip to content
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

TST: Check error raised when inserting wrong length categorical column #29523

Conversation

ryankarlos
Copy link
Contributor

@ryankarlos ryankarlos commented Nov 10, 2019

@@ -724,6 +724,13 @@ def test_astype_duplicate_col(self):
expected = concat([a1_str, b, a2_str], axis=1)
tm.assert_frame_equal(result, expected)

def test_wrong_length_cat_dtype_raises(self):
cat = pd.Categorical.from_codes([0, 1, 1, 0, 1, 2], ["a", "b", "c"])
Copy link
Member

Choose a reason for hiding this comment

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

Could you add the issue number here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@gfyoung gfyoung added Categorical Categorical Data Type DataFrame DataFrame data structure labels Nov 10, 2019
@gfyoung gfyoung added this to the 1.0 milestone Nov 10, 2019
@gfyoung gfyoung added the Testing pandas testing functions or related to the test suite label Nov 10, 2019
@ryankarlos
Copy link
Contributor Author

ryankarlos commented Nov 10, 2019

Any ides why CI is failing on Linux Py36 ? Doesn't seem related to my additions - having similar issue in #29522

=================================== FAILURES ===================================
______________ test_chunks_have_consistent_numerical_type[python] ______________
[gw0] linux -- Python 3.6.1 /home/vsts/miniconda3/envs/pandas-dev/bin/python

all_parsers = <pandas.tests.io.parser.conftest.PythonParser object at 0x7fb4c86cb5f8>

    def test_chunks_have_consistent_numerical_type(all_parsers):
        parser = all_parsers
        integers = [str(i) for i in range(499999)]
        data = "a\n" + "\n".join(integers + ["1.0", "2.0"] + integers)
    
        # Coercions should work without warnings.
        with tm.assert_produces_warning(None):
>           result = parser.read_csv(StringIO(data))

pandas/tests/io/parser/test_common.py:1204: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <contextlib._GeneratorContextManager object at 0x7fb48ad70390>
type = None, value = None, traceback = None

    def __exit__(self, type, value, traceback):
        if type is None:
            try:
>               next(self.gen)
E               AssertionError: Caused unexpected warning(s): [('ResourceWarning', ResourceWarning("unclosed file <_io.BufferedReader name='test1.xlsx'>",), '/home/vsts/work/1/s/pandas/io/parsers.py', 2927)].

@mroeschke
Copy link
Member

Just a flakey test: #29514

Could you try pushing again?

@ryankarlos ryankarlos force-pushed the TST-inserting-wrong-length-categorical-in-df branch from 549c872 to 8bbe8ee Compare November 10, 2019 18:27
@ryankarlos
Copy link
Contributor Author

Ok just repushed - waiting for CI

@alimcmaster1
Copy link
Member

CI failures still related to that test #29514

@ryankarlos ryankarlos force-pushed the TST-inserting-wrong-length-categorical-in-df branch from 8bbe8ee to 551d855 Compare November 13, 2019 01:26
@ryankarlos
Copy link
Contributor Author

Thanks - will try repushing again and see if it works now.

@jreback jreback changed the title TST: Check error raised when inserting wrong length catgerical column TST: Check error raised when inserting wrong length categorical column Nov 13, 2019
# GH29523
cat = pd.Categorical.from_codes([0, 1, 1, 0, 1, 2], ["a", "b", "c"])
df = pd.DataFrame({"bar": range(10)})
err = "Length of values does not match length of index"
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this test to pandas/tests/frame/test_indexing.py in the class TestDataFrameIndexingCategorical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ryankarlos ryankarlos force-pushed the TST-inserting-wrong-length-categorical-in-df branch from fdbcbea to 27de8fb Compare November 13, 2019 01:58
@jreback jreback merged commit 7a13fc4 into pandas-dev:master Nov 16, 2019
@jreback
Copy link
Contributor

jreback commented Nov 16, 2019

thanks @ryankarlos

@ryankarlos ryankarlos deleted the TST-inserting-wrong-length-categorical-in-df branch November 16, 2019 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type DataFrame DataFrame data structure Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: inserting a Categorical with the wrong length into a DataFrame is allowed
5 participants