BUG: String indexing against object dtype may raise AttributeError #14424

Merged
merged 1 commit into from Oct 22, 2016

Conversation

Projects
None yet
3 participants
Member

sinhrks commented Oct 14, 2016

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

String indexing may raise AttributeError, rather than KeyError.

df = pd.DataFrame([1], pd.Index([pd.Timestamp('2011-01-01')], dtype=object))
df.index.is_all_dates
# True
df['2011']
# AttributeError: 'Index' object has no attribute '_get_string_slice'

sinhrks added this to the 0.19.1 milestone Oct 14, 2016

codecov-io commented Oct 14, 2016 edited

Current coverage is 85.25% (diff: 100%)

Merging #14424 into master will increase coverage by <.01%

@@             master     #14424   diff @@
==========================================
  Files           140        140          
  Lines         50631      50632     +1   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43167      43168     +1   
  Misses         7464       7464          
  Partials          0          0          

Powered by Codecov. Last update 7cad3f1...ae22dce

@@ -2936,6 +2936,9 @@ def _wrap_joined_index(self, joined, other):
name = self.name if self.name == other.name else None
return Index(joined, name=name)
+ def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
@jorisvandenbossche

jorisvandenbossche Oct 14, 2016

Owner

Can you add a docstring or comment explaining where this is overwritten / used ?

@sinhrks

sinhrks Oct 16, 2016

Member

sure, added the comment.

Small comment, looks good for the rest

@jorisvandenbossche jorisvandenbossche merged commit 233d51d into pandas-dev:master Oct 22, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@sinhrks Thanks!

sinhrks deleted the sinhrks:partial_string_bug branch Oct 23, 2016

@jorisvandenbossche jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Nov 2, 2016

@sinhrks @jorisvandenbossche sinhrks + jorisvandenbossche [Backport #14424] BUG: String indexing against object dtype may raise…
… AttributeError (#14424)

(cherry picked from commit 233d51d)
920122c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment