7
7
8
8
from pandas import (
9
9
Series ,
10
- Timedelta ,
11
10
)
12
11
import pandas ._testing as tm
13
12
14
13
15
14
@pytest .mark .parametrize (
16
15
"arr,dtype,expected" ,
17
16
[
18
- (
19
- np .array ([8.5 , 8.6 , 8.7 , 8.8 , 8.9999999999995 ]),
20
- "infer" ,
21
- np .array ([8.5 , 8.6 , 8.7 , 8.8 , 8.9999999999995 ]),
22
- ),
23
- (
24
- np .array ([8.0 , 8.0 , 8.0 , 8.0 , 8.9999999999995 ]),
25
- "infer" ,
26
- np .array ([8 , 8 , 8 , 8 , 9 ], dtype = np .int64 ),
27
- ),
28
- (
29
- np .array ([8.0 , 8.0 , 8.0 , 8.0 , 9.0000000000005 ]),
30
- "infer" ,
31
- np .array ([8 , 8 , 8 , 8 , 9 ], dtype = np .int64 ),
32
- ),
33
17
(
34
18
# This is a judgement call, but we do _not_ downcast Decimal
35
19
# objects
36
20
np .array ([decimal .Decimal ("0.0" )]),
37
- "int64" ,
21
+ np . dtype ( "int64" ) ,
38
22
np .array ([decimal .Decimal ("0.0" )]),
39
23
),
40
- (
41
- # GH#45837
42
- np .array ([Timedelta (days = 1 ), Timedelta (days = 2 )], dtype = object ),
43
- "infer" ,
44
- np .array ([1 , 2 ], dtype = "m8[D]" ).astype ("m8[ns]" ),
45
- ),
46
- # TODO: similar for dt64, dt64tz, Period, Interval?
47
24
],
48
25
)
49
26
def test_downcast (arr , expected , dtype ):
@@ -60,26 +37,6 @@ def test_downcast_booleans():
60
37
tm .assert_numpy_array_equal (result , expected )
61
38
62
39
63
- def test_downcast_conversion_no_nan (any_real_numpy_dtype ):
64
- dtype = any_real_numpy_dtype
65
- expected = np .array ([1 , 2 ])
66
- arr = np .array ([1.0 , 2.0 ], dtype = dtype )
67
-
68
- result = maybe_downcast_to_dtype (arr , "infer" )
69
- tm .assert_almost_equal (result , expected , check_dtype = False )
70
-
71
-
72
- def test_downcast_conversion_nan (float_numpy_dtype ):
73
- dtype = float_numpy_dtype
74
- data = [1.0 , 2.0 , np .nan ]
75
-
76
- expected = np .array (data , dtype = dtype )
77
- arr = np .array (data , dtype = dtype )
78
-
79
- result = maybe_downcast_to_dtype (arr , "infer" )
80
- tm .assert_almost_equal (result , expected )
81
-
82
-
83
40
def test_downcast_conversion_empty (any_real_numpy_dtype ):
84
41
dtype = any_real_numpy_dtype
85
42
arr = np .array ([], dtype = dtype )
@@ -89,7 +46,7 @@ def test_downcast_conversion_empty(any_real_numpy_dtype):
89
46
90
47
@pytest .mark .parametrize ("klass" , [np .datetime64 , np .timedelta64 ])
91
48
def test_datetime_likes_nan (klass ):
92
- dtype = klass .__name__ + "[ns]"
49
+ dtype = np . dtype ( klass .__name__ + "[ns]" )
93
50
arr = np .array ([1 , 2 , np .nan ])
94
51
95
52
exp = np .array ([1 , 2 , klass ("NaT" )], dtype )
0 commit comments