25
25
)
26
26
27
27
28
- @pytest .fixture (params = [True , False ])
29
- def pandas_dtype (request ):
30
- return request .param
31
-
32
-
33
28
def test_infer_dtype_from_int_scalar (any_int_numpy_dtype ):
34
29
# Test that infer_dtype_from_scalar is
35
30
# returning correct dtype for int and float.
@@ -81,36 +76,32 @@ def test_infer_dtype_from_timedelta(data):
81
76
82
77
83
78
@pytest .mark .parametrize ("freq" , ["M" , "D" ])
84
- def test_infer_dtype_from_period (freq , pandas_dtype ):
79
+ def test_infer_dtype_from_period (freq ):
85
80
p = Period ("2011-01-01" , freq = freq )
86
- dtype , val = infer_dtype_from_scalar (p , pandas_dtype = pandas_dtype )
81
+ dtype , val = infer_dtype_from_scalar (p )
87
82
88
- if pandas_dtype :
89
- exp_dtype = f"period[{ freq } ]"
90
- else :
91
- exp_dtype = np .object_
83
+ exp_dtype = f"period[{ freq } ]"
92
84
93
85
assert dtype == exp_dtype
94
86
assert val == p
95
87
96
88
97
- @pytest .mark .parametrize (
98
- "data" , [date (2000 , 1 , 1 ), "foo" , Timestamp (1 , tz = "US/Eastern" )]
99
- )
100
- def test_infer_dtype_misc (data ):
101
- dtype , val = infer_dtype_from_scalar (data )
89
+ def test_infer_dtype_misc ():
90
+ dt = date (2000 , 1 , 1 )
91
+ dtype , val = infer_dtype_from_scalar (dt )
102
92
assert dtype == np .object_
103
93
94
+ ts = Timestamp (1 , tz = "US/Eastern" )
95
+ dtype , val = infer_dtype_from_scalar (ts )
96
+ assert dtype == "datetime64[ns, US/Eastern]"
97
+
104
98
105
99
@pytest .mark .parametrize ("tz" , ["UTC" , "US/Eastern" , "Asia/Tokyo" ])
106
- def test_infer_from_scalar_tz (tz , pandas_dtype ):
100
+ def test_infer_from_scalar_tz (tz ):
107
101
dt = Timestamp (1 , tz = tz )
108
- dtype , val = infer_dtype_from_scalar (dt , pandas_dtype = pandas_dtype )
102
+ dtype , val = infer_dtype_from_scalar (dt )
109
103
110
- if pandas_dtype :
111
- exp_dtype = f"datetime64[ns, { tz } ]"
112
- else :
113
- exp_dtype = np .object_
104
+ exp_dtype = f"datetime64[ns, { tz } ]"
114
105
115
106
assert dtype == exp_dtype
116
107
assert val == dt
@@ -126,11 +117,11 @@ def test_infer_from_scalar_tz(tz, pandas_dtype):
126
117
(Timedelta (0 ), Timedelta (1 ), "timedelta64[ns]" ),
127
118
],
128
119
)
129
- def test_infer_from_interval (left , right , subtype , closed , pandas_dtype ):
120
+ def test_infer_from_interval (left , right , subtype , closed ):
130
121
# GH 30337
131
122
interval = Interval (left , right , closed )
132
- result_dtype , result_value = infer_dtype_from_scalar (interval , pandas_dtype )
133
- expected_dtype = f"interval[{ subtype } , { closed } ]" if pandas_dtype else np . object_
123
+ result_dtype , result_value = infer_dtype_from_scalar (interval )
124
+ expected_dtype = f"interval[{ subtype } , { closed } ]"
134
125
assert result_dtype == expected_dtype
135
126
assert result_value == interval
136
127
@@ -143,54 +134,49 @@ def test_infer_dtype_from_scalar_errors():
143
134
144
135
145
136
@pytest .mark .parametrize (
146
- "value, expected, pandas_dtype " ,
137
+ "value, expected" ,
147
138
[
148
- ("foo" , np .object_ , False ),
149
- (b"foo" , np .object_ , False ),
150
- (1 , np .int64 , False ),
151
- (1.5 , np .float_ , False ),
152
- (np .datetime64 ("2016-01-01" ), np .dtype ("M8[ns]" ), False ),
153
- (Timestamp ("20160101" ), np .dtype ("M8[ns]" ), False ),
154
- (Timestamp ("20160101" , tz = "UTC" ), np .object_ , False ),
155
- (Timestamp ("20160101" , tz = "UTC" ), "datetime64[ns, UTC]" , True ),
139
+ ("foo" , np .object_ ),
140
+ (b"foo" , np .object_ ),
141
+ (1 , np .int64 ),
142
+ (1.5 , np .float_ ),
143
+ (np .datetime64 ("2016-01-01" ), np .dtype ("M8[ns]" )),
144
+ (Timestamp ("20160101" ), np .dtype ("M8[ns]" )),
145
+ (Timestamp ("20160101" , tz = "UTC" ), "datetime64[ns, UTC]" ),
156
146
],
157
147
)
158
- def test_infer_dtype_from_scalar (value , expected , pandas_dtype ):
159
- dtype , _ = infer_dtype_from_scalar (value , pandas_dtype = pandas_dtype )
148
+ def test_infer_dtype_from_scalar (value , expected ):
149
+ dtype , _ = infer_dtype_from_scalar (value )
160
150
assert is_dtype_equal (dtype , expected )
161
151
162
152
with pytest .raises (TypeError , match = "must be list-like" ):
163
- infer_dtype_from_array (value , pandas_dtype = pandas_dtype )
153
+ infer_dtype_from_array (value )
164
154
165
155
166
156
@pytest .mark .parametrize (
167
- "arr, expected, pandas_dtype " ,
157
+ "arr, expected" ,
168
158
[
169
- ([1 ], np .int_ , False ),
170
- (np .array ([1 ], dtype = np .int64 ), np .int64 , False ),
171
- ([np .nan , 1 , "" ], np .object_ , False ),
172
- (np .array ([[1.0 , 2.0 ]]), np .float_ , False ),
173
- (Categorical (list ("aabc" )), np .object_ , False ),
174
- (Categorical ([1 , 2 , 3 ]), np .int64 , False ),
175
- (Categorical (list ("aabc" )), "category" , True ),
176
- (Categorical ([1 , 2 , 3 ]), "category" , True ),
177
- (date_range ("20160101" , periods = 3 ), np .dtype ("=M8[ns]" ), False ),
159
+ ([1 ], np .int_ ),
160
+ (np .array ([1 ], dtype = np .int64 ), np .int64 ),
161
+ ([np .nan , 1 , "" ], np .object_ ),
162
+ (np .array ([[1.0 , 2.0 ]]), np .float_ ),
163
+ (Categorical (list ("aabc" )), "category" ),
164
+ (Categorical ([1 , 2 , 3 ]), "category" ),
165
+ (date_range ("20160101" , periods = 3 ), np .dtype ("=M8[ns]" )),
178
166
(
179
167
date_range ("20160101" , periods = 3 , tz = "US/Eastern" ),
180
168
"datetime64[ns, US/Eastern]" ,
181
- True ,
182
169
),
183
- (Series ([1.0 , 2 , 3 ]), np .float64 , False ),
184
- (Series (list ("abc" )), np .object_ , False ),
170
+ (Series ([1.0 , 2 , 3 ]), np .float64 ),
171
+ (Series (list ("abc" )), np .object_ ),
185
172
(
186
173
Series (date_range ("20160101" , periods = 3 , tz = "US/Eastern" )),
187
174
"datetime64[ns, US/Eastern]" ,
188
- True ,
189
175
),
190
176
],
191
177
)
192
- def test_infer_dtype_from_array (arr , expected , pandas_dtype ):
193
- dtype , _ = infer_dtype_from_array (arr , pandas_dtype = pandas_dtype )
178
+ def test_infer_dtype_from_array (arr , expected ):
179
+ dtype , _ = infer_dtype_from_array (arr )
194
180
assert is_dtype_equal (dtype , expected )
195
181
196
182
0 commit comments