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

BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead #14580

Closed
navin-k80 opened this issue Nov 3, 2016 · 2 comments
Labels
Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@navin-k80
Copy link

A small, complete example of the issue

# Your code here
>>> type(pd.Series([1,2,3]).astype('category').iloc[0:1])
<class 'pandas.core.series.Series'>

>>> type(pd.Series([1,2,3]).astype('category').iloc[np.array([0, 1])])
<class 'pandas.core.categorical.Categorical'>

Expected Output

Both should return a pandas Series object

Output of pd.show_versions()

pandas version = 0.18
@navin-k80 navin-k80 changed the title iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead Nov 3, 2016
@jreback
Copy link
Contributor

jreback commented Nov 3, 2016

in 0.19.0

In [18]: pd.Series([1,2,3]).astype('category').iloc[0:1]
Out[18]: 
0    1
dtype: category
Categories (3, int64): [1, 2, 3]

In [19]: pd.Series([1,2,3]).astype('category').iloc[np.array([0, 1])]
Out[19]: 
[1, 2]
Categories (3, int64): [1, 2, 3]

could be #12531 (in 0.18.1) or in 0.19.0

@jreback jreback closed this as completed Nov 3, 2016
@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 3, 2016
@jreback jreback added this to the No action milestone Nov 3, 2016
@jreback
Copy link
Contributor

jreback commented Nov 3, 2016

actually, I stand corrected. This is a different treatment of slices vs list-like
so this is a bug.

In [16]: s = pd.Series([1,2,3]).astype('category')

In [17]: type(s.iloc[[0,1]])
Out[17]: pandas.core.categorical.Categorical

In [18]: type(s.iloc[0:1])
Out[18]: pandas.core.series.Series

@jreback jreback reopened this Nov 3, 2016
@jreback jreback modified the milestones: No action, Next Major Release Nov 3, 2016
@jreback jreback added Difficulty Novice Categorical Categorical Data Type labels Nov 3, 2016
nathalier added a commit to nathalier/pandas that referenced this issue Nov 12, 2016
Before, iloc on pd.Series returned Categorical object  for list-like  indexes input, while Series object is expected.

Fixes pandas-dev#14580
nathalier added a commit to nathalier/pandas that referenced this issue Nov 12, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Nov 12, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Nov 13, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Nov 20, 2016
Before, iloc on pd.Series returned Categorical object  for list-like  indexes input, while Series object is expected.

Fixes pandas-dev#14580
nathalier added a commit to nathalier/pandas that referenced this issue Nov 20, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Nov 20, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Dec 18, 2016
Before, iloc on pd.Series returned Categorical object  for list-like  indexes input, while Series object is expected.

Fixes pandas-dev#14580
nathalier added a commit to nathalier/pandas that referenced this issue Dec 18, 2016
Add test to verify type of returned value of iloc() Series of Categorical data.
nathalier added a commit to nathalier/pandas that referenced this issue Dec 18, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
2 participants