14
14
from numpy .random import randn
15
15
import numpy as np
16
16
17
- from pandas import (DataFrame , Series , Index , MultiIndex , date_range , NaT ,
18
- timedelta_range , Timestamp , Categorical , SparseDataFrame )
17
+ from pandas import (DataFrame , Series , date_range , timedelta_range ,
18
+ Categorical , SparseDataFrame )
19
+ import pandas as pd
20
+
21
+ from pandas .util .testing import (assert_almost_equal ,
22
+ assert_series_equal ,
23
+ assert_frame_equal )
19
24
20
25
import pandas .util .testing as tm
21
26
@@ -70,19 +75,19 @@ def test_get_value(self, float_frame):
70
75
71
76
def test_add_prefix_suffix (self , float_frame ):
72
77
with_prefix = float_frame .add_prefix ('foo#' )
73
- expected = Index (['foo#%s' % c for c in float_frame .columns ])
78
+ expected = pd . Index (['foo#%s' % c for c in float_frame .columns ])
74
79
tm .assert_index_equal (with_prefix .columns , expected )
75
80
76
81
with_suffix = float_frame .add_suffix ('#foo' )
77
- expected = Index (['%s#foo' % c for c in float_frame .columns ])
82
+ expected = pd . Index (['%s#foo' % c for c in float_frame .columns ])
78
83
tm .assert_index_equal (with_suffix .columns , expected )
79
84
80
85
with_pct_prefix = float_frame .add_prefix ('%' )
81
- expected = Index (['%{}' .format (c ) for c in float_frame .columns ])
86
+ expected = pd . Index (['%{}' .format (c ) for c in float_frame .columns ])
82
87
tm .assert_index_equal (with_pct_prefix .columns , expected )
83
88
84
89
with_pct_suffix = float_frame .add_suffix ('%' )
85
- expected = Index (['{}%' .format (c ) for c in float_frame .columns ])
90
+ expected = pd . Index (['{}%' .format (c ) for c in float_frame .columns ])
86
91
tm .assert_index_equal (with_pct_suffix .columns , expected )
87
92
88
93
def test_get_axis (self , float_frame ):
@@ -123,21 +128,21 @@ def test_column_contains_typeerror(self, float_frame):
123
128
124
129
def test_tab_completion (self ):
125
130
# DataFrame whose columns are identifiers shall have them in __dir__.
126
- df = DataFrame ([list ('abcd' ), list ('efgh' )], columns = list ('ABCD' ))
131
+ df = pd . DataFrame ([list ('abcd' ), list ('efgh' )], columns = list ('ABCD' ))
127
132
for key in list ('ABCD' ):
128
133
assert key in dir (df )
129
- assert isinstance (df .__getitem__ ('A' ), Series )
134
+ assert isinstance (df .__getitem__ ('A' ), pd . Series )
130
135
131
136
# DataFrame whose first-level columns are identifiers shall have
132
137
# them in __dir__.
133
- df = DataFrame ([ list ( 'abcd' ), list ( 'efgh' )],
134
- columns = MultiIndex . from_tuples ( list (zip ( 'ABCD' ,
135
- 'EFGH' ))))
138
+ df = pd . DataFrame (
139
+ [ list ( 'abcd' ), list ('efgh' )] ,
140
+ columns = pd . MultiIndex . from_tuples ( list ( zip ( 'ABCD' , 'EFGH' ))))
136
141
for key in list ('ABCD' ):
137
142
assert key in dir (df )
138
143
for key in list ('EFGH' ):
139
144
assert key not in dir (df )
140
- assert isinstance (df .__getitem__ ('A' ), DataFrame )
145
+ assert isinstance (df .__getitem__ ('A' ), pd . DataFrame )
141
146
142
147
def test_not_hashable (self , empty_frame ):
143
148
df = self .klass ([1 ])
@@ -309,7 +314,7 @@ def test_values(self, float_frame, float_string_frame):
309
314
# single block corner case
310
315
arr = float_frame [['A' , 'B' ]].values
311
316
expected = float_frame .reindex (columns = ['A' , 'B' ]).values
312
- tm . assert_almost_equal (arr , expected )
317
+ assert_almost_equal (arr , expected )
313
318
314
319
def test_transpose (self , float_frame ):
315
320
frame = float_frame
@@ -342,11 +347,11 @@ def test_axis_aliases(self, float_frame):
342
347
# reg name
343
348
expected = f .sum (axis = 0 )
344
349
result = f .sum (axis = 'index' )
345
- tm . assert_series_equal (result , expected )
350
+ assert_series_equal (result , expected )
346
351
347
352
expected = f .sum (axis = 1 )
348
353
result = f .sum (axis = 'columns' )
349
- tm . assert_series_equal (result , expected )
354
+ assert_series_equal (result , expected )
350
355
351
356
def test_class_axis (self ):
352
357
# GH 18147
@@ -360,7 +365,7 @@ def test_more_values(self, float_string_frame):
360
365
361
366
def test_repr_with_mi_nat (self , float_string_frame ):
362
367
df = self .klass ({'X' : [1 , 2 ]},
363
- index = [[NaT , Timestamp ('20130101' )], ['a' , 'b' ]])
368
+ index = [[pd . NaT , pd . Timestamp ('20130101' )], ['a' , 'b' ]])
364
369
res = repr (df )
365
370
exp = ' X\n NaT a 1\n 2013-01-01 b 2'
366
371
assert res == exp
@@ -405,8 +410,8 @@ class TestDataFrameMisc(SharedWithSparse):
405
410
406
411
klass = DataFrame
407
412
# SharedWithSparse tests use generic, klass-agnostic assertion
408
- _assert_frame_equal = staticmethod (tm . assert_frame_equal )
409
- _assert_series_equal = staticmethod (tm . assert_series_equal )
413
+ _assert_frame_equal = staticmethod (assert_frame_equal )
414
+ _assert_series_equal = staticmethod (assert_series_equal )
410
415
411
416
def test_values (self , float_frame ):
412
417
float_frame .values [:, 0 ] = 5.
@@ -415,8 +420,7 @@ def test_values(self, float_frame):
415
420
def test_as_matrix_deprecated (self , float_frame ):
416
421
# GH 18458
417
422
with tm .assert_produces_warning (FutureWarning ):
418
- cols = float_frame .columns .tolist ()
419
- result = float_frame .as_matrix (columns = cols )
423
+ result = float_frame .as_matrix (columns = float_frame .columns .tolist ())
420
424
expected = float_frame .values
421
425
tm .assert_numpy_array_equal (result , expected )
422
426
0 commit comments