Skip to content

pandas cat identifiers do not display correctly when referenced using dict-like syntax #2060

Description

@PhilipYip1988

Some identifiers do not display correctly from a dict-like reference such as a value in a dict or a Series from a DataFrame:

import random
import string
import numpy as np
import pandas as pd
random.seed(0)

df1 = pd.DataFrame({'grades1': random.choices(['a', 'b', 'c', 'd', 'e'], k=30),
                    'grades2': random.choices(['a', 'b', 'c', 'd', 'e'], k=30)})

df1['grades1'] = df1['grades1'].astype('category')
df1['grades2'] = df1['grades2'].astype('category')

For example using:

df1['grades1'].cat.<tab>

Image

Image

Should give consistent behaviour to accessing the identifier via the attribute:

df1.grades1.cat.<tab>

Image

Image

I originally posted this as ipython issue 14819 but was told to post here as it seems to be an issue with jedi and the identifiers display correctly when:

%config Completer.use_jedi = False
import random
import string
import numpy as np
import pandas as pd
random.seed(0)

df1 = pd.DataFrame({'grades1': random.choices(['a', 'b', 'c', 'd', 'e'], k=30),
                    'grades2': random.choices(['a', 'b', 'c', 'd', 'e'], k=30)})

df1['grades1'] = df1['grades1'].astype('category')
df1['grades2'] = df1['grades2'].astype('category')

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions