Skip to content

BUG/TST: reset setitem_copy on object enlargement #5584

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 4 commits into from
Nov 29, 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
15 changes: 12 additions & 3 deletions pandas/computation/tests/test_eval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

import unittest
import functools
from itertools import product

Expand Down Expand Up @@ -104,10 +103,11 @@ def _is_py3_complex_incompat(result, expected):
_good_arith_ops = com.difference(_arith_ops_syms, _special_case_arith_ops_syms)


class TestEvalNumexprPandas(unittest.TestCase):
class TestEvalNumexprPandas(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestEvalNumexprPandas, cls).setUpClass()
skip_if_no_ne()
import numexpr as ne
cls.ne = ne
Expand All @@ -116,6 +116,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
super(TestEvalNumexprPandas, cls).tearDownClass()
del cls.engine, cls.parser
if hasattr(cls, 'ne'):
del cls.ne
Expand Down Expand Up @@ -707,6 +708,7 @@ class TestEvalNumexprPython(TestEvalNumexprPandas):

@classmethod
def setUpClass(cls):
super(TestEvalNumexprPython, cls).setUpClass()
skip_if_no_ne()
import numexpr as ne
cls.ne = ne
Expand All @@ -733,6 +735,7 @@ class TestEvalPythonPython(TestEvalNumexprPython):

@classmethod
def setUpClass(cls):
super(TestEvalPythonPython, cls).setUpClass()
cls.engine = 'python'
cls.parser = 'python'

Expand Down Expand Up @@ -761,6 +764,7 @@ class TestEvalPythonPandas(TestEvalPythonPython):

@classmethod
def setUpClass(cls):
super(TestEvalPythonPandas, cls).setUpClass()
cls.engine = 'python'
cls.parser = 'pandas'

Expand Down Expand Up @@ -1024,17 +1028,19 @@ def test_performance_warning_for_poor_alignment(self):
#------------------------------------
# slightly more complex ops

class TestOperationsNumExprPandas(unittest.TestCase):
class TestOperationsNumExprPandas(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestOperationsNumExprPandas, cls).setUpClass()
skip_if_no_ne()
cls.engine = 'numexpr'
cls.parser = 'pandas'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms

@classmethod
def tearDownClass(cls):
super(TestOperationsNumExprPandas, cls).tearDownClass()
del cls.engine, cls.parser

def eval(self, *args, **kwargs):
Expand Down Expand Up @@ -1337,6 +1343,7 @@ class TestOperationsNumExprPython(TestOperationsNumExprPandas):

@classmethod
def setUpClass(cls):
super(TestOperationsNumExprPython, cls).setUpClass()
if not _USE_NUMEXPR:
raise nose.SkipTest("numexpr engine not installed")
cls.engine = 'numexpr'
Expand Down Expand Up @@ -1404,6 +1411,7 @@ class TestOperationsPythonPython(TestOperationsNumExprPython):

@classmethod
def setUpClass(cls):
super(TestOperationsPythonPython, cls).setUpClass()
cls.engine = cls.parser = 'python'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
Expand All @@ -1414,6 +1422,7 @@ class TestOperationsPythonPandas(TestOperationsNumExprPandas):

@classmethod
def setUpClass(cls):
super(TestOperationsPythonPandas, cls).setUpClass()
cls.engine = 'python'
cls.parser = 'pandas'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ def _ixs(self, i, axis=0, copy=False):

# a location index by definition
i = _maybe_convert_indices(i, len(self._get_axis(axis)))
return self.reindex(i, takeable=True)
return self.reindex(i, takeable=True)._setitem_copy(True)
else:
new_values, copy = self._data.fast_2d_xs(i, copy=copy)
return Series(new_values, index=self.columns,
Expand Down Expand Up @@ -2714,7 +2714,7 @@ def trans(v):

self._clear_item_cache()
else:
return self.take(indexer, axis=axis, convert=False)
return self.take(indexer, axis=axis, convert=False, is_copy=False)

def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):
"""
Expand Down Expand Up @@ -2760,7 +2760,7 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False):

self._clear_item_cache()
else:
return self.take(indexer, axis=axis, convert=False)
return self.take(indexer, axis=axis, convert=False, is_copy=False)

def swaplevel(self, i, j, axis=0):
"""
Expand Down
18 changes: 12 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def __delitem__(self, key):
except KeyError:
pass

def take(self, indices, axis=0, convert=True):
def take(self, indices, axis=0, convert=True, is_copy=True):
"""
Analogous to ndarray.take

Expand All @@ -1073,6 +1073,7 @@ def take(self, indices, axis=0, convert=True):
indices : list / array of ints
axis : int, default 0
convert : translate neg to pos indices (default)
is_copy : mark the returned frame as a copy

Returns
-------
Expand All @@ -1090,12 +1091,17 @@ def take(self, indices, axis=0, convert=True):
labels = self._get_axis(axis)
new_items = labels.take(indices)
new_data = self._data.reindex_axis(new_items, indexer=indices,
axis=0)
axis=baxis)
else:
new_data = self._data.take(indices, axis=baxis, verify=convert)
return self._constructor(new_data)\
._setitem_copy(True)\
.__finalize__(self)
new_data = self._data.take(indices, axis=baxis)

result = self._constructor(new_data).__finalize__(self)

# maybe set copy if we didn't actually change the index
if is_copy and not result._get_axis(axis).equals(self._get_axis(axis)):
result = result._setitem_copy(is_copy)

return result

# TODO: Check if this was clearer in 0.12
def select(self, crit, axis=0):
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def _setitem_with_indexer(self, indexer, value):
labels = _safe_append_to_index(index, key)
self.obj._data = self.obj.reindex_axis(labels, i)._data
self.obj._maybe_update_cacher(clear=True)
self.obj._setitem_copy(False)

if isinstance(labels, MultiIndex):
self.obj.sortlevel(inplace=True)
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/tests/test_clipboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import unittest

import numpy as np
from numpy.random import randint

Expand All @@ -18,9 +16,10 @@
raise nose.SkipTest("no clipboard found")


class TestClipboard(unittest.TestCase):
class TestClipboard(tm.TestCase):
@classmethod
def setUpClass(cls):
super(TestClipboard, cls).setUpClass()
cls.data = {}
cls.data['string'] = mkdf(5, 3, c_idx_type='s', r_idx_type='i',
c_idx_names=[None], r_idx_names=[None])
Expand All @@ -43,6 +42,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
super(TestClipboard, cls).tearDownClass()
del cls.data_types, cls.data

def check_round_trip_frame(self, data_type, excel=None, sep=None):
Expand Down
5 changes: 2 additions & 3 deletions pandas/io/tests/test_cparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import sys
import re
import unittest

import nose

Expand All @@ -32,7 +31,7 @@
import pandas.parser as parser


class TestCParser(unittest.TestCase):
class TestCParser(tm.TestCase):

def setUp(self):
self.dirpath = tm.get_data_path()
Expand Down Expand Up @@ -132,7 +131,7 @@ def test_integer_thousands(self):

expected = [123456, 12500]
tm.assert_almost_equal(result[0], expected)

def test_integer_thousands_alt(self):
data = '123.456\n12.500'

Expand Down
20 changes: 13 additions & 7 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function
from pandas import compat
import unittest
import warnings
import nose
from nose.tools import assert_equal
Expand Down Expand Up @@ -35,15 +34,17 @@ def assert_n_failed_equals_n_null_columns(wngs, obj, cls=SymbolWarning):
assert msgs.str.contains('|'.join(failed_symbols)).all()


class TestGoogle(unittest.TestCase):
class TestGoogle(tm.TestCase):
@classmethod
def setUpClass(cls):
super(TestGoogle, cls).setUpClass()
cls.locales = tm.get_locales(prefix='en_US')
if not cls.locales:
raise nose.SkipTest("US English locale not available for testing")

@classmethod
def tearDownClass(cls):
super(TestGoogle, cls).tearDownClass()
del cls.locales

@network
Expand Down Expand Up @@ -105,9 +106,10 @@ def test_get_multi2(self):
assert_n_failed_equals_n_null_columns(w, result)


class TestYahoo(unittest.TestCase):
class TestYahoo(tm.TestCase):
@classmethod
def setUpClass(cls):
super(TestYahoo, cls).setUpClass()
_skip_if_no_lxml()

@network
Expand Down Expand Up @@ -224,9 +226,10 @@ def test_get_date_ret_index(self):
assert np.issubdtype(pan.values.dtype, np.floating)


class TestYahooOptions(unittest.TestCase):
class TestYahooOptions(tm.TestCase):
@classmethod
def setUpClass(cls):
super(TestYahooOptions, cls).setUpClass()
_skip_if_no_lxml()

# aapl has monthlies
Expand All @@ -241,6 +244,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
super(TestYahooOptions, cls).tearDownClass()
del cls.aapl, cls.expiry

@network
Expand Down Expand Up @@ -283,9 +287,10 @@ def test_get_put_data(self):
assert len(puts)>1


class TestOptionsWarnings(unittest.TestCase):
class TestOptionsWarnings(tm.TestCase):
@classmethod
def setUpClass(cls):
super(TestOptionsWarnings, cls).setUpClass()
_skip_if_no_lxml()

with assert_produces_warning(FutureWarning):
Expand All @@ -300,6 +305,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
super(TestOptionsWarnings, cls).tearDownClass()
del cls.aapl, cls.year, cls.month

@network
Expand Down Expand Up @@ -342,7 +348,7 @@ def test_get_put_data_warning(self):
warnings.warn("IndexError thrown no tables found")


class TestDataReader(unittest.TestCase):
class TestDataReader(tm.TestCase):
def test_is_s3_url(self):
from pandas.io.common import _is_s3_url
self.assert_(_is_s3_url("s3://pandas/somethingelse.com"))
Expand Down Expand Up @@ -372,7 +378,7 @@ def test_read_famafrench(self):
assert isinstance(ff, dict)


class TestFred(unittest.TestCase):
class TestFred(tm.TestCase):
@network
def test_fred(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions pandas/io/tests/test_date_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import sys
import re
import unittest

import nose

Expand All @@ -22,9 +21,9 @@
from pandas import compat
from pandas.lib import Timestamp
import pandas.io.date_converters as conv
import pandas.util.testing as tm


class TestConverters(unittest.TestCase):
class TestConverters(tm.TestCase):

def setUp(self):
self.years = np.array([2007, 2008])
Expand Down
Loading