diff --git a/pandas/core/frame.py b/pandas/core/frame.py index dd41075ddf92e..1f29d477ee20b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -217,6 +217,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None, dtype = self._validate_dtype(dtype) if isinstance(data, DataFrame): + data = data.iloc[:,:] data = data._data if isinstance(data, BlockManager): diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 9df72053fb0af..1a7636cca39b0 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -752,9 +752,6 @@ def _getitem_tuple(self, tup): if i >= self.obj.ndim: raise IndexingError('Too many indexers') - if is_null_slice(key): - continue - retval = getattr(retval, self.name)._getitem_axis(key, axis=i) return retval @@ -1171,8 +1168,6 @@ def _tuplify(self, loc): def _get_slice_axis(self, slice_obj, axis=0): obj = self.obj - if not need_slice(slice_obj): - return obj indexer = self._convert_slice_indexer(slice_obj, axis) if isinstance(indexer, slice): @@ -1244,8 +1239,7 @@ def _getbool_axis(self, key, axis=0): def _get_slice_axis(self, slice_obj, axis=0): """ this is pretty simple as we just have to deal with labels """ obj = self.obj - if not need_slice(slice_obj): - return obj + labels = obj._get_axis(axis) indexer = labels.slice_indexer(slice_obj.start, slice_obj.stop, @@ -1461,9 +1455,9 @@ def _getitem_tuple(self, tup): if i >= self.obj.ndim: raise IndexingError('Too many indexers') - if is_null_slice(key): - axis += 1 - continue + #if is_null_slice(key): + # axis += 1 + # continue retval = getattr(retval, self.name)._getitem_axis(key, axis=axis) @@ -1477,10 +1471,6 @@ def _getitem_tuple(self, tup): return retval def _get_slice_axis(self, slice_obj, axis=0): - obj = self.obj - - if not need_slice(slice_obj): - return obj slice_obj = self._convert_slice_indexer(slice_obj, axis) if isinstance(slice_obj, slice): @@ -1792,12 +1782,6 @@ def is_label_like(key): return not isinstance(key, slice) and not is_list_like_indexer(key) -def need_slice(obj): - return (obj.start is not None or - obj.stop is not None or - (obj.step is not None and obj.step != 1)) - - def maybe_droplevels(index, key): # drop levels original_index = index diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 09de3bf4a8046..5d9ce5de92ef5 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -2637,6 +2637,7 @@ def test_constructor_dtype_copy(self): def test_constructor_dtype_nocast_view(self): df = DataFrame([[1, 2]]) should_be_view = DataFrame(df, dtype=df[0].dtype) + self.assertTrue(should_be_view._is_view) should_be_view[0][0] = 99 self.assertEqual(df.values[0, 0], 99) diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index c6d80a08ad61a..0cebaab2f2a3c 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -4912,6 +4912,14 @@ def test_maybe_numeric_slice(self): expected = [1] self.assertEqual(result, expected) + def test_empty_indexers_return_view(self): + # Closes Issue 11814 + df = pd.DataFrame({'col1':range(10,20), + 'col2':range(20,30)}) + self.assertTrue(df.loc[:,:]._is_view) + self.assertTrue(df.iloc[:,:]._is_view) + self.assertTrue(df.ix[:,:]._is_view) + class TestCategoricalIndex(tm.TestCase): @@ -5196,6 +5204,7 @@ def test_boolean_selection(self): self.assertRaises(TypeError, lambda : df4[df4.index < 2]) self.assertRaises(TypeError, lambda : df4[df4.index > 1]) + class TestSeriesNoneCoercion(tm.TestCase): EXPECTED_RESULTS = [ # For numeric series, we should coerce to NaN.