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