Skip to content

BUG: ensure index casting works even in Int64Index #3322

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

Merged
merged 1 commit into from
Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ pandas 0.11.0
- fixed pretty priniting of sets (GH3294_)
- Panel() and Panel.from_dict() now respects ordering when give OrderedDict (GH3303_)
- DataFrame where with a datetimelike incorrectly selecting (GH3311_)
- Ensure index casts work even in Int64Index

.. _GH3294: https://github.com/pydata/pandas/issues/3294
.. _GH622: https://github.com/pydata/pandas/issues/622
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,11 @@ def inferred_type(self):
def _constructor(self):
return Int64Index

@cache_readonly
def _engine(self):
# property, for now, slow to look up
return self._engine_type(lambda: com._ensure_int64(self.values), len(self))

@property
def asi8(self):
# do not cache or you'll create a memory leak
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,17 @@ def test_set_index(self):
self.assertRaises(Exception, setattr, self.mixed_frame, 'index',
idx[::2])

def test_set_index_cast(self):

# issue casting an index then set_index
df = DataFrame({'A' : [1.1,2.2,3.3], 'B' : [5.0,6.1,7.2]},
index = [2010,2011,2012])
expected = df.ix[2010]
new_index = df.index.astype(np.int32)
df.index = new_index
result = df.ix[2010]
assert_series_equal(result,expected)

def test_set_index2(self):
df = DataFrame({'A': ['foo', 'foo', 'foo', 'bar', 'bar'],
'B': ['one', 'two', 'three', 'one', 'two'],
Expand Down