Skip to content

BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical, fixes #14580 #14642

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

Closed
wants to merge 4 commits into from

Conversation

nathalier
Copy link
Contributor

@nathalier nathalier commented Nov 12, 2016

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

closes #14580

@jreback jreback changed the title Fixes bug #14580 BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead Nov 12, 2016
@jreback jreback changed the title BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical, fixes #14580 Nov 12, 2016
@jreback jreback added Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 12, 2016
@@ -409,6 +409,23 @@ def test_getitem_callable(self):
result = s[lambda x: [True, False, True, True]]
tm.assert_series_equal(result, s.iloc[[0, 2, 3]])

def test_getitem_category_type(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

put this in the test_categorical.py instead

@@ -1595,6 +1595,15 @@ def _get_slice_axis(self, slice_obj, axis=0):
else:
return self.obj.take(slice_obj, axis=axis, convert=False)

def _get_list_axis(self, key_list, axis=0):

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 add a comment on what this is doing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you give a hint on phrasing please?
Would "return Series values by list or array of integers" be clear enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

so ideally add a Paramaters/Returns section (I know we don't have docs for other of the internal functions, but have to start :))

yes but be clear that this is a posiitional indexer

@codecov-io
Copy link

codecov-io commented Nov 12, 2016

Current coverage is 84.53% (diff: 90.00%)

Merging #14642 into master will decrease coverage by 0.02%

@@             master     #14642   diff @@
==========================================
  Files           144        144          
  Lines         51058      51061     +3   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          43177      43166    -11   
- Misses         7881       7895    +14   
  Partials          0          0          

Powered by Codecov. Last update e503d40...f6b1790

@nathalier
Copy link
Contributor Author

It looks like appveyor CI check failed due to connectivity problem. Is it possible to restart it?

@nathalier nathalier force-pushed the nath-working branch 2 times, most recently from cddb441 to c7454ea Compare November 20, 2016 14:18
@jorisvandenbossche
Copy link
Member

@nathalier Can you add a whatsnew note for this?


# get slice
result = s.iloc[0:1]
self.assertEqual(type(result), type(s))
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 use tm.assert_series_equal for these (IOW, construct the expected series)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback Thank you! Corrected.

Before, iloc on pd.Series returned Categorical object  for list-like  indexes input, while Series object is expected.

Fixes pandas-dev#14580
 _get_list_axis() is factored out of _getitem_axis() to handle list-like type of input.
Add test to verify type of returned value of iloc() Series of Categorical data.
@nathalier
Copy link
Contributor Author

@jorisvandenbossche I added whatsnew to 0.19.2. Is it OK?

@jreback jreback added this to the 0.20.0 milestone Dec 30, 2016
@jreback jreback closed this in 7dd451d Dec 30, 2016
@jreback
Copy link
Contributor

jreback commented Dec 30, 2016

thanks!

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
Development

Successfully merging this pull request may close these issues.

BUG: iloc misbehavior with pd.Series: sometimes returns pd.Categorical instead
4 participants