1
- from io import StringIO
2
-
3
1
import numpy as np
2
+ import pytest
4
3
5
4
import pandas as pd
6
5
from pandas import DataFrame , DatetimeIndex , Series , date_range , timedelta_range
@@ -19,33 +18,6 @@ def assert_range_equal(left, right):
19
18
20
19
21
20
class TestTimeSeries :
22
- def test_autocorr (self , datetime_series ):
23
- # Just run the function
24
- corr1 = datetime_series .autocorr ()
25
-
26
- # Now run it with the lag parameter
27
- corr2 = datetime_series .autocorr (lag = 1 )
28
-
29
- # corr() with lag needs Series of at least length 2
30
- if len (datetime_series ) <= 2 :
31
- assert np .isnan (corr1 )
32
- assert np .isnan (corr2 )
33
- else :
34
- assert corr1 == corr2
35
-
36
- # Choose a random lag between 1 and length of Series - 2
37
- # and compare the result with the Series corr() function
38
- n = 1 + np .random .randint (max (1 , len (datetime_series ) - 2 ))
39
- corr1 = datetime_series .corr (datetime_series .shift (n ))
40
- corr2 = datetime_series .autocorr (lag = n )
41
-
42
- # corr() with lag needs Series of at least length 2
43
- if len (datetime_series ) <= 2 :
44
- assert np .isnan (corr1 )
45
- assert np .isnan (corr2 )
46
- else :
47
- assert corr1 == corr2
48
-
49
21
def test_mpl_compat_hack (self , datetime_series ):
50
22
51
23
# This is currently failing because the test was relying on
@@ -79,13 +51,6 @@ def test_contiguous_boolean_preserve_freq(self):
79
51
masked = rng [mask ]
80
52
assert masked .freq is None
81
53
82
- def test_series_ctor_datetime64 (self ):
83
- rng = date_range ("1/1/2000 00:00:00" , "1/1/2000 1:59:50" , freq = "10s" )
84
- dates = np .asarray (rng )
85
-
86
- series = Series (dates )
87
- assert np .issubdtype (series .dtype , np .dtype ("M8[ns]" ))
88
-
89
54
def test_promote_datetime_date (self ):
90
55
rng = date_range ("1/1/2000" , periods = 20 )
91
56
ts = Series (np .random .randn (20 ), index = rng )
@@ -123,15 +88,6 @@ def test_groupby_count_dateparseerror(self):
123
88
124
89
tm .assert_series_equal (result , expected )
125
90
126
- def test_to_csv_numpy_16_bug (self ):
127
- frame = DataFrame ({"a" : date_range ("1/1/2000" , periods = 10 )})
128
-
129
- buf = StringIO ()
130
- frame .to_csv (buf )
131
-
132
- result = buf .getvalue ()
133
- assert "2000-01-01" in result
134
-
135
91
def test_series_map_box_timedelta (self ):
136
92
# GH 11349
137
93
s = Series (timedelta_range ("1 day 1 s" , periods = 5 , freq = "h" ))
@@ -175,6 +131,19 @@ def test_view_tz(self):
175
131
)
176
132
tm .assert_series_equal (result , expected )
177
133
134
+ @pytest .mark .parametrize ("tz" , [None , "US/Central" ])
135
+ def test_asarray_object_dt64 (self , tz ):
136
+ ser = pd .Series (pd .date_range ("2000" , periods = 2 , tz = tz ))
137
+
138
+ with tm .assert_produces_warning (None ):
139
+ # Future behavior (for tzaware case) with no warning
140
+ result = np .asarray (ser , dtype = object )
141
+
142
+ expected = np .array (
143
+ [pd .Timestamp ("2000-01-01" , tz = tz ), pd .Timestamp ("2000-01-02" , tz = tz )]
144
+ )
145
+ tm .assert_numpy_array_equal (result , expected )
146
+
178
147
def test_asarray_tz_naive (self ):
179
148
# This shouldn't produce a warning.
180
149
ser = pd .Series (pd .date_range ("2000" , periods = 2 ))
@@ -183,12 +152,6 @@ def test_asarray_tz_naive(self):
183
152
184
153
tm .assert_numpy_array_equal (result , expected )
185
154
186
- # optionally, object
187
- result = np .asarray (ser , dtype = object )
188
-
189
- expected = np .array ([pd .Timestamp ("2000-01-01" ), pd .Timestamp ("2000-01-02" )])
190
- tm .assert_numpy_array_equal (result , expected )
191
-
192
155
def test_asarray_tz_aware (self ):
193
156
tz = "US/Central"
194
157
ser = pd .Series (pd .date_range ("2000" , periods = 2 , tz = tz ))
@@ -201,11 +164,3 @@ def test_asarray_tz_aware(self):
201
164
result = np .asarray (ser , dtype = "M8[ns]" )
202
165
203
166
tm .assert_numpy_array_equal (result , expected )
204
-
205
- # Future behavior with no warning
206
- expected = np .array (
207
- [pd .Timestamp ("2000-01-01" , tz = tz ), pd .Timestamp ("2000-01-02" , tz = tz )]
208
- )
209
- result = np .asarray (ser , dtype = object )
210
-
211
- tm .assert_numpy_array_equal (result , expected )
0 commit comments