@@ -59,7 +59,7 @@ def _axes(self):
59
59
""" return the axes for my object typ """
60
60
return self ._typ ._AXIS_ORDERS
61
61
62
- def _construct (self , shape , value = None , ** kwargs ):
62
+ def _construct (self , shape , value = None , dtype = None , ** kwargs ):
63
63
""" construct an object for the given shape
64
64
if value is specified use that if its a scalar
65
65
if value is an array, repeat it as needed """
@@ -74,7 +74,7 @@ def _construct(self, shape, value=None, **kwargs):
74
74
# remove the info axis
75
75
kwargs .pop (self ._typ ._info_axis_name ,None )
76
76
else :
77
- arr = np .empty (shape )
77
+ arr = np .empty (shape , dtype = dtype )
78
78
arr .fill (value )
79
79
else :
80
80
fshape = np .prod (shape )
@@ -184,6 +184,32 @@ def test_numpy_1_7_compat_numeric_methods(self):
184
184
if f is not None :
185
185
f (o )
186
186
187
+ def test_downcast (self ):
188
+ # test close downcasting
189
+
190
+ o = self ._construct (shape = 4 , value = 9 , dtype = np .int64 )
191
+ result = o .copy ()
192
+ result ._data = o ._data .downcast (dtypes = 'infer' )
193
+ self ._compare (result , o )
194
+
195
+ o = self ._construct (shape = 4 , value = 9. )
196
+ expected = o .astype (np .int64 )
197
+ result = o .copy ()
198
+ result ._data = o ._data .downcast (dtypes = 'infer' )
199
+ self ._compare (result , expected )
200
+
201
+ o = self ._construct (shape = 4 , value = 9.5 )
202
+ result = o .copy ()
203
+ result ._data = o ._data .downcast (dtypes = 'infer' )
204
+ self ._compare (result , o )
205
+
206
+ # are close
207
+ o = self ._construct (shape = 4 , value = 9.000000000005 )
208
+ result = o .copy ()
209
+ result ._data = o ._data .downcast (dtypes = 'infer' )
210
+ expected = o .astype (np .int64 )
211
+ self ._compare (result , expected )
212
+
187
213
class TestSeries (unittest .TestCase , Generic ):
188
214
_typ = Series
189
215
_comparator = lambda self , x , y : assert_series_equal (x ,y )
@@ -335,7 +361,7 @@ def test_interp_quad(self):
335
361
_skip_if_no_scipy ()
336
362
sq = Series ([1 , 4 , np .nan , 16 ], index = [1 , 2 , 3 , 4 ])
337
363
result = sq .interpolate (method = 'quadratic' )
338
- expected = Series ([1. , 4. , 9. , 16. ], index = [1 , 2 , 3 , 4 ])
364
+ expected = Series ([1 , 4 , 9 , 16 ], index = [1 , 2 , 3 , 4 ])
339
365
assert_series_equal (result , expected )
340
366
341
367
def test_interp_scipy_basic (self ):
@@ -589,7 +615,7 @@ def test_spline(self):
589
615
_skip_if_no_scipy ()
590
616
s = Series ([1 , 2 , np .nan , 4 , 5 , np .nan , 7 ])
591
617
result = s .interpolate (method = 'spline' , order = 1 )
592
- expected = Series ([1. , 2 , 3 , 4 , 5 , 6 , 7 ]) # dtype?
618
+ expected = Series ([1 , 2 , 3 , 4 , 5 , 6 , 7 ])
593
619
assert_series_equal (result , expected )
594
620
595
621
0 commit comments