Skip to content

Commit eea1b62

Browse files
committed
Restore test code shared with SparseSeries tests
1 parent f9ec1ec commit eea1b62

File tree

7 files changed

+104
-100
lines changed

7 files changed

+104
-100
lines changed

pandas/sparse/tests/test_sparse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from pandas.sparse.tests.test_array import assert_sp_array_equal
3535

3636
import pandas.tests.test_panel as test_panel
37-
import pandas.tests.test_series as test_series
37+
from pandas.tests.series.test_misc_api import SharedWithSparse
3838

3939
dec = np.testing.dec
4040

@@ -116,7 +116,7 @@ def assert_sp_panel_equal(left, right, exact_indices=True):
116116
assert (item in left)
117117

118118

119-
class TestSparseSeries(tm.TestCase, test_series.CheckNameIntegration):
119+
class TestSparseSeries(tm.TestCase, SharedWithSparse):
120120
_multiprocess_can_split_ = True
121121

122122
def setUp(self):

pandas/tests/series/test_analytics.py

-8
Original file line numberDiff line numberDiff line change
@@ -1615,14 +1615,6 @@ def test_is_unique(self):
16151615
s = Series(np.arange(1000))
16161616
self.assertTrue(s.is_unique)
16171617

1618-
def test_argsort_preserve_name(self):
1619-
result = self.ts.argsort()
1620-
self.assertEqual(result.name, self.ts.name)
1621-
1622-
def test_sort_index_name(self):
1623-
result = self.ts.sort_index(ascending=False)
1624-
self.assertEqual(result.name, self.ts.name)
1625-
16261618
def test_sort_values(self):
16271619

16281620
ts = self.ts.copy()

pandas/tests/series/test_combine_concat.py

-8
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ def test_concat_empty_series_dtypes(self):
183183
self.assertEqual(result.dtype, np.object_)
184184
self.assertEqual(result.ftype, 'object:dense')
185185

186-
def test_combine_first_name(self):
187-
result = self.ts.combine_first(self.ts[:5])
188-
self.assertEqual(result.name, self.ts.name)
189-
190186
def test_combine_first_dt64(self):
191187
from pandas.tseries.tools import to_datetime
192188
s0 = to_datetime(Series(["2010", np.NaN]))
@@ -200,7 +196,3 @@ def test_combine_first_dt64(self):
200196
rs = s0.combine_first(s1)
201197
xp = Series([datetime(2010, 1, 1), '2011'])
202198
assert_series_equal(rs, xp)
203-
204-
def test_append_preserve_name(self):
205-
result = self.ts[:5].append(self.ts[5:])
206-
self.assertEqual(result.name, self.ts.name)

pandas/tests/series/test_indexing.py

-10
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ def f():
111111
assert_series_equal(s, Series(dtype='int64', index=Index(
112112
[], dtype='object')))
113113

114-
def test_getitem_preserve_name(self):
115-
result = self.ts[self.ts > 0]
116-
self.assertEqual(result.name, self.ts.name)
117-
118-
result = self.ts[[0, 2, 4]]
119-
self.assertEqual(result.name, self.ts.name)
120-
121-
result = self.ts[5:10]
122-
self.assertEqual(result.name, self.ts.name)
123-
124114
def test_getitem_setitem_ellipsis(self):
125115
s = Series(np.random.randn(10))
126116

pandas/tests/series/test_io.py

-13
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ class TestSeriesIO(TestData, tm.TestCase):
2020

2121
_multiprocess_can_split_ = True
2222

23-
def test_pickle(self):
24-
unp_series = self._pickle_roundtrip(self.series)
25-
unp_ts = self._pickle_roundtrip(self.ts)
26-
assert_series_equal(unp_series, self.series)
27-
assert_series_equal(unp_ts, self.ts)
28-
29-
def _pickle_roundtrip(self, obj):
30-
31-
with ensure_clean() as path:
32-
obj.to_pickle(path)
33-
unpickled = pd.read_pickle(path)
34-
return unpickled
35-
3623
def test_from_csv(self):
3724

3825
with ensure_clean() as path:

pandas/tests/series/test_misc_api.py

+102-23
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,113 @@
1010

1111
from pandas.compat import range
1212
from pandas import compat
13-
from pandas.util.testing import assert_series_equal
13+
from pandas.util.testing import (assert_series_equal,
14+
ensure_clean)
1415
import pandas.util.testing as tm
1516

1617
from .common import TestData
1718

1819

19-
class TestSeriesMisc(TestData, tm.TestCase):
20+
class SharedWithSparse(object):
21+
22+
def test_scalarop_preserve_name(self):
23+
result = self.ts * 2
24+
self.assertEqual(result.name, self.ts.name)
25+
26+
def test_copy_name(self):
27+
result = self.ts.copy()
28+
self.assertEqual(result.name, self.ts.name)
29+
30+
def test_copy_index_name_checking(self):
31+
# don't want to be able to modify the index stored elsewhere after
32+
# making a copy
33+
34+
self.ts.index.name = None
35+
self.assertIsNone(self.ts.index.name)
36+
self.assertIs(self.ts, self.ts)
37+
38+
cp = self.ts.copy()
39+
cp.index.name = 'foo'
40+
com.pprint_thing(self.ts.index.name)
41+
self.assertIsNone(self.ts.index.name)
42+
43+
def test_append_preserve_name(self):
44+
result = self.ts[:5].append(self.ts[5:])
45+
self.assertEqual(result.name, self.ts.name)
46+
47+
def test_binop_maybe_preserve_name(self):
48+
# names match, preserve
49+
result = self.ts * self.ts
50+
self.assertEqual(result.name, self.ts.name)
51+
result = self.ts.mul(self.ts)
52+
self.assertEqual(result.name, self.ts.name)
53+
54+
result = self.ts * self.ts[:-2]
55+
self.assertEqual(result.name, self.ts.name)
56+
57+
# names don't match, don't preserve
58+
cp = self.ts.copy()
59+
cp.name = 'something else'
60+
result = self.ts + cp
61+
self.assertIsNone(result.name)
62+
result = self.ts.add(cp)
63+
self.assertIsNone(result.name)
64+
65+
ops = ['add', 'sub', 'mul', 'div', 'truediv', 'floordiv', 'mod', 'pow']
66+
ops = ops + ['r' + op for op in ops]
67+
for op in ops:
68+
# names match, preserve
69+
s = self.ts.copy()
70+
result = getattr(s, op)(s)
71+
self.assertEqual(result.name, self.ts.name)
72+
73+
# names don't match, don't preserve
74+
cp = self.ts.copy()
75+
cp.name = 'changed'
76+
result = getattr(s, op)(cp)
77+
self.assertIsNone(result.name)
78+
79+
def test_combine_first_name(self):
80+
result = self.ts.combine_first(self.ts[:5])
81+
self.assertEqual(result.name, self.ts.name)
82+
83+
def test_getitem_preserve_name(self):
84+
result = self.ts[self.ts > 0]
85+
self.assertEqual(result.name, self.ts.name)
86+
87+
result = self.ts[[0, 2, 4]]
88+
self.assertEqual(result.name, self.ts.name)
89+
90+
result = self.ts[5:10]
91+
self.assertEqual(result.name, self.ts.name)
92+
93+
def test_pickle(self):
94+
unp_series = self._pickle_roundtrip(self.series)
95+
unp_ts = self._pickle_roundtrip(self.ts)
96+
assert_series_equal(unp_series, self.series)
97+
assert_series_equal(unp_ts, self.ts)
98+
99+
def _pickle_roundtrip(self, obj):
100+
101+
with ensure_clean() as path:
102+
obj.to_pickle(path)
103+
unpickled = pd.read_pickle(path)
104+
return unpickled
105+
106+
def test_argsort_preserve_name(self):
107+
result = self.ts.argsort()
108+
self.assertEqual(result.name, self.ts.name)
109+
110+
def test_sort_index_name(self):
111+
result = self.ts.sort_index(ascending=False)
112+
self.assertEqual(result.name, self.ts.name)
113+
114+
def test_to_sparse_pass_name(self):
115+
result = self.ts.to_sparse()
116+
self.assertEqual(result.name, self.ts.name)
117+
118+
119+
class TestSeriesMisc(TestData, SharedWithSparse, tm.TestCase):
20120

21121
_multiprocess_can_split_ = True
22122

@@ -144,27 +244,6 @@ def test_numpy_unique(self):
144244
# it works!
145245
np.unique(self.ts)
146246

147-
def test_copy_name(self):
148-
result = self.ts.copy()
149-
self.assertEqual(result.name, self.ts.name)
150-
151-
def test_copy_index_name_checking(self):
152-
# don't want to be able to modify the index stored elsewhere after
153-
# making a copy
154-
155-
self.ts.index.name = None
156-
self.assertIsNone(self.ts.index.name)
157-
self.assertIs(self.ts, self.ts)
158-
159-
cp = self.ts.copy()
160-
cp.index.name = 'foo'
161-
com.pprint_thing(self.ts.index.name)
162-
self.assertIsNone(self.ts.index.name)
163-
164-
def test_to_sparse_pass_name(self):
165-
result = self.ts.to_sparse()
166-
self.assertEqual(result.name, self.ts.name)
167-
168247
def test_ndarray_compat(self):
169248

170249
# test numpy compat with Series as sub-class of NDFrame

pandas/tests/series/test_operators.py

-36
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,6 @@ class TestSeriesOperators(TestData, tm.TestCase):
2828

2929
_multiprocess_can_split_ = True
3030

31-
def test_binop_maybe_preserve_name(self):
32-
# names match, preserve
33-
result = self.ts * self.ts
34-
self.assertEqual(result.name, self.ts.name)
35-
result = self.ts.mul(self.ts)
36-
self.assertEqual(result.name, self.ts.name)
37-
38-
result = self.ts * self.ts[:-2]
39-
self.assertEqual(result.name, self.ts.name)
40-
41-
# names don't match, don't preserve
42-
cp = self.ts.copy()
43-
cp.name = 'something else'
44-
result = self.ts + cp
45-
self.assertIsNone(result.name)
46-
result = self.ts.add(cp)
47-
self.assertIsNone(result.name)
48-
49-
ops = ['add', 'sub', 'mul', 'div', 'truediv', 'floordiv', 'mod', 'pow']
50-
ops = ops + ['r' + op for op in ops]
51-
for op in ops:
52-
# names match, preserve
53-
s = self.ts.copy()
54-
result = getattr(s, op)(s)
55-
self.assertEqual(result.name, self.ts.name)
56-
57-
# names don't match, don't preserve
58-
cp = self.ts.copy()
59-
cp.name = 'changed'
60-
result = getattr(s, op)(cp)
61-
self.assertIsNone(result.name)
62-
6331
def test_comparisons(self):
6432
left = np.random.randn(10)
6533
right = np.random.randn(10)
@@ -1407,7 +1375,3 @@ def test_datetime64_with_index(self):
14071375
df['expected'] = df['date'] - df.index.to_series()
14081376
df['result'] = df['date'] - df.index
14091377
assert_series_equal(df['result'], df['expected'], check_names=False)
1410-
1411-
def test_scalarop_preserve_name(self):
1412-
result = self.ts * 2
1413-
self.assertEqual(result.name, self.ts.name)

0 commit comments

Comments
 (0)