2424
2525import pandas .io .formats .printing as printing
2626
27- from .common import TestData
28-
2927
3028class SharedWithSparse :
3129 """
@@ -39,82 +37,84 @@ def _assert_series_equal(self, left, right):
3937 """Dispatch to series class dependent assertion"""
4038 raise NotImplementedError
4139
42- def test_scalarop_preserve_name (self ):
43- result = self . ts * 2
44- assert result .name == self . ts .name
40+ def test_scalarop_preserve_name (self , datetime_series ):
41+ result = datetime_series * 2
42+ assert result .name == datetime_series .name
4543
46- def test_copy_name (self ):
47- result = self . ts .copy ()
48- assert result .name == self . ts .name
44+ def test_copy_name (self , datetime_series ):
45+ result = datetime_series .copy ()
46+ assert result .name == datetime_series .name
4947
50- def test_copy_index_name_checking (self ):
48+ def test_copy_index_name_checking (self , datetime_series ):
5149 # don't want to be able to modify the index stored elsewhere after
5250 # making a copy
5351
54- self . ts .index .name = None
55- assert self . ts .index .name is None
56- assert self . ts is self . ts
52+ datetime_series .index .name = None
53+ assert datetime_series .index .name is None
54+ assert datetime_series is datetime_series
5755
58- cp = self . ts .copy ()
56+ cp = datetime_series .copy ()
5957 cp .index .name = "foo"
60- printing .pprint_thing (self . ts .index .name )
61- assert self . ts .index .name is None
58+ printing .pprint_thing (datetime_series .index .name )
59+ assert datetime_series .index .name is None
6260
63- def test_append_preserve_name (self ):
64- result = self . ts [:5 ].append (self . ts [5 :])
65- assert result .name == self . ts .name
61+ def test_append_preserve_name (self , datetime_series ):
62+ result = datetime_series [:5 ].append (datetime_series [5 :])
63+ assert result .name == datetime_series .name
6664
67- def test_binop_maybe_preserve_name (self ):
65+ def test_binop_maybe_preserve_name (self , datetime_series ):
6866 # names match, preserve
69- result = self . ts * self . ts
70- assert result .name == self . ts .name
71- result = self . ts . mul (self . ts )
72- assert result .name == self . ts .name
67+ result = datetime_series * datetime_series
68+ assert result .name == datetime_series .name
69+ result = datetime_series . mul (datetime_series )
70+ assert result .name == datetime_series .name
7371
74- result = self . ts * self . ts [:- 2 ]
75- assert result .name == self . ts .name
72+ result = datetime_series * datetime_series [:- 2 ]
73+ assert result .name == datetime_series .name
7674
7775 # names don't match, don't preserve
78- cp = self . ts .copy ()
76+ cp = datetime_series .copy ()
7977 cp .name = "something else"
80- result = self . ts + cp
78+ result = datetime_series + cp
8179 assert result .name is None
82- result = self . ts .add (cp )
80+ result = datetime_series .add (cp )
8381 assert result .name is None
8482
8583 ops = ["add" , "sub" , "mul" , "div" , "truediv" , "floordiv" , "mod" , "pow" ]
8684 ops = ops + ["r" + op for op in ops ]
8785 for op in ops :
8886 # names match, preserve
89- s = self . ts .copy ()
87+ s = datetime_series .copy ()
9088 result = getattr (s , op )(s )
91- assert result .name == self . ts .name
89+ assert result .name == datetime_series .name
9290
9391 # names don't match, don't preserve
94- cp = self . ts .copy ()
92+ cp = datetime_series .copy ()
9593 cp .name = "changed"
9694 result = getattr (s , op )(cp )
9795 assert result .name is None
9896
99- def test_combine_first_name (self ):
100- result = self .ts .combine_first (self .ts [:5 ])
101- assert result .name == self .ts .name
97+ def test_combine_first_name (self , datetime_series ):
98+ result = datetime_series .combine_first (datetime_series [:5 ])
99+ assert result .name == datetime_series .name
100+
101+ def test_getitem_preserve_name (self , datetime_series ):
102+ result = datetime_series [datetime_series > 0 ]
103+ assert result .name == datetime_series .name
102104
103- def test_getitem_preserve_name (self ):
104- result = self .ts [self .ts > 0 ]
105- assert result .name == self .ts .name
105+ result = datetime_series [[0 , 2 , 4 ]]
106+ assert result .name == datetime_series .name
106107
107- result = self . ts [[ 0 , 2 , 4 ] ]
108- assert result .name == self . ts .name
108+ result = datetime_series [ 5 : 10 ]
109+ assert result .name == datetime_series .name
109110
110- result = self .ts [5 :10 ]
111- assert result .name == self .ts .name
111+ def test_pickle_datetimes (self , datetime_series ):
112+ unp_ts = self ._pickle_roundtrip (datetime_series )
113+ assert_series_equal (unp_ts , datetime_series )
112114
113- def test_pickle (self ):
114- unp_series = self ._pickle_roundtrip (self .series )
115- unp_ts = self ._pickle_roundtrip (self .ts )
116- assert_series_equal (unp_series , self .series )
117- assert_series_equal (unp_ts , self .ts )
115+ def test_pickle_strings (self , string_series ):
116+ unp_series = self ._pickle_roundtrip (string_series )
117+ assert_series_equal (unp_series , string_series )
118118
119119 def _pickle_roundtrip (self , obj ):
120120
@@ -123,13 +123,13 @@ def _pickle_roundtrip(self, obj):
123123 unpickled = pd .read_pickle (path )
124124 return unpickled
125125
126- def test_argsort_preserve_name (self ):
127- result = self . ts .argsort ()
128- assert result .name == self . ts .name
126+ def test_argsort_preserve_name (self , datetime_series ):
127+ result = datetime_series .argsort ()
128+ assert result .name == datetime_series .name
129129
130- def test_sort_index_name (self ):
131- result = self . ts .sort_index (ascending = False )
132- assert result .name == self . ts .name
130+ def test_sort_index_name (self , datetime_series ):
131+ result = datetime_series .sort_index (ascending = False )
132+ assert result .name == datetime_series .name
133133
134134 def test_constructor_dict (self ):
135135 d = {"a" : 0.0 , "b" : 1.0 , "c" : 2.0 }
@@ -211,7 +211,7 @@ def test_sparse_accessor_updates_on_inplace(self):
211211 assert s .sparse .density == 1.0
212212
213213
214- class TestSeriesMisc (TestData , SharedWithSparse ):
214+ class TestSeriesMisc (SharedWithSparse ):
215215
216216 series_klass = Series
217217 # SharedWithSparse tests use generic, series_klass-agnostic assertion
@@ -307,44 +307,49 @@ def test_not_hashable(self):
307307 with pytest .raises (TypeError , match = msg ):
308308 hash (s )
309309
310- def test_contains (self ):
311- tm .assert_contains_all (self . ts . index , self . ts )
310+ def test_contains (self , datetime_series ):
311+ tm .assert_contains_all (datetime_series . index , datetime_series )
312312
313- def test_iter (self ):
314- for i , val in enumerate (self . series ):
315- assert val == self . series [i ]
313+ def test_iter_datetimes (self , datetime_series ):
314+ for i , val in enumerate (datetime_series ):
315+ assert val == datetime_series [i ]
316316
317- for i , val in enumerate (self .ts ):
318- assert val == self .ts [i ]
317+ def test_iter_strings (self , string_series ):
318+ for i , val in enumerate (string_series ):
319+ assert val == string_series [i ]
319320
320- def test_keys (self ):
321+ def test_keys (self , datetime_series ):
321322 # HACK: By doing this in two stages, we avoid 2to3 wrapping the call
322323 # to .keys() in a list()
323- getkeys = self . ts .keys
324- assert getkeys () is self . ts .index
324+ getkeys = datetime_series .keys
325+ assert getkeys () is datetime_series .index
325326
326- def test_values (self ):
327- tm .assert_almost_equal (self .ts .values , self .ts , check_dtype = False )
327+ def test_values (self , datetime_series ):
328+ tm .assert_almost_equal (
329+ datetime_series .values , datetime_series , check_dtype = False
330+ )
328331
329- def test_iteritems (self ):
330- for idx , val in self . series .iteritems ():
331- assert val == self . series [idx ]
332+ def test_iteritems_datetimes (self , datetime_series ):
333+ for idx , val in datetime_series .iteritems ():
334+ assert val == datetime_series [idx ]
332335
333- for idx , val in self .ts .iteritems ():
334- assert val == self .ts [idx ]
336+ def test_iteritems_strings (self , string_series ):
337+ for idx , val in string_series .iteritems ():
338+ assert val == string_series [idx ]
335339
336340 # assert is lazy (genrators don't define reverse, lists do)
337- assert not hasattr (self . series .iteritems (), "reverse" )
341+ assert not hasattr (string_series .iteritems (), "reverse" )
338342
339- def test_items (self ):
340- for idx , val in self . series .items ():
341- assert val == self . series [idx ]
343+ def test_items_datetimes (self , datetime_series ):
344+ for idx , val in datetime_series .items ():
345+ assert val == datetime_series [idx ]
342346
343- for idx , val in self .ts .items ():
344- assert val == self .ts [idx ]
347+ def test_items_strings (self , string_series ):
348+ for idx , val in string_series .items ():
349+ assert val == string_series [idx ]
345350
346351 # assert is lazy (genrators don't define reverse, lists do)
347- assert not hasattr (self . series .items (), "reverse" )
352+ assert not hasattr (string_series .items (), "reverse" )
348353
349354 def test_raise_on_info (self ):
350355 s = Series (np .random .randn (10 ))
@@ -413,9 +418,9 @@ def test_class_axis(self):
413418 # no exception and no empty docstring
414419 assert pydoc .getdoc (Series .index )
415420
416- def test_numpy_unique (self ):
421+ def test_numpy_unique (self , datetime_series ):
417422 # it works!
418- np .unique (self . ts )
423+ np .unique (datetime_series )
419424
420425 def test_ndarray_compat (self ):
421426
0 commit comments