44import numpy as np
55from pandas .compat import zip
66
7- from pandas import (Series , Index , isna ,
8- to_datetime , DatetimeIndex , Timestamp ,
9- Interval , IntervalIndex , Categorical ,
7+ from pandas import (Series , isna , to_datetime , DatetimeIndex ,
8+ Timestamp , Interval , IntervalIndex , Categorical ,
109 cut , qcut , date_range )
1110import pandas .util .testing as tm
1211from pandas .api .types import CategoricalDtype as CDT
@@ -29,7 +28,8 @@ def test_bins(self):
2928 result , bins = cut (data , 3 , retbins = True )
3029
3130 intervals = IntervalIndex .from_breaks (bins .round (3 ))
32- expected = intervals .take ([0 , 0 , 0 , 1 , 2 , 0 ]).astype ('category' )
31+ intervals = intervals .take ([0 , 0 , 0 , 1 , 2 , 0 ])
32+ expected = Categorical (intervals , ordered = True )
3333 tm .assert_categorical_equal (result , expected )
3434 tm .assert_almost_equal (bins , np .array ([0.1905 , 3.36666667 ,
3535 6.53333333 , 9.7 ]))
@@ -38,7 +38,8 @@ def test_right(self):
3838 data = np .array ([.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 , 2.575 ])
3939 result , bins = cut (data , 4 , right = True , retbins = True )
4040 intervals = IntervalIndex .from_breaks (bins .round (3 ))
41- expected = intervals .astype ('category' ).take ([0 , 0 , 0 , 2 , 3 , 0 , 0 ])
41+ expected = Categorical (intervals , ordered = True )
42+ expected = expected .take ([0 , 0 , 0 , 2 , 3 , 0 , 0 ])
4243 tm .assert_categorical_equal (result , expected )
4344 tm .assert_almost_equal (bins , np .array ([0.1905 , 2.575 , 4.95 ,
4445 7.325 , 9.7 ]))
@@ -47,7 +48,8 @@ def test_noright(self):
4748 data = np .array ([.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 , 2.575 ])
4849 result , bins = cut (data , 4 , right = False , retbins = True )
4950 intervals = IntervalIndex .from_breaks (bins .round (3 ), closed = 'left' )
50- expected = intervals .take ([0 , 0 , 0 , 2 , 3 , 0 , 1 ]).astype ('category' )
51+ intervals = intervals .take ([0 , 0 , 0 , 2 , 3 , 0 , 1 ])
52+ expected = Categorical (intervals , ordered = True )
5153 tm .assert_categorical_equal (result , expected )
5254 tm .assert_almost_equal (bins , np .array ([0.2 , 2.575 , 4.95 ,
5355 7.325 , 9.7095 ]))
@@ -56,7 +58,8 @@ def test_arraylike(self):
5658 data = [.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 ]
5759 result , bins = cut (data , 3 , retbins = True )
5860 intervals = IntervalIndex .from_breaks (bins .round (3 ))
59- expected = intervals .take ([0 , 0 , 0 , 1 , 2 , 0 ]).astype ('category' )
61+ intervals = intervals .take ([0 , 0 , 0 , 1 , 2 , 0 ])
62+ expected = Categorical (intervals , ordered = True )
6063 tm .assert_categorical_equal (result , expected )
6164 tm .assert_almost_equal (bins , np .array ([0.1905 , 3.36666667 ,
6265 6.53333333 , 9.7 ]))
@@ -249,8 +252,8 @@ def test_qcut_nas(self):
249252
250253 def test_qcut_index (self ):
251254 result = qcut ([0 , 2 ], 2 )
252- expected = Index ( [Interval (- 0.001 , 1 ), Interval (1 , 2 )]). astype (
253- 'category' )
255+ intervals = [Interval (- 0.001 , 1 ), Interval (1 , 2 )]
256+ expected = Categorical ( intervals , ordered = True )
254257 tm .assert_categorical_equal (result , expected )
255258
256259 def test_round_frac (self ):
0 commit comments