16
16
Series ,
17
17
date_range ,
18
18
option_context ,
19
- reset_option ,
20
- set_option ,
21
19
)
22
- import pandas ._testing as tm
23
20
24
21
25
22
@pytest .fixture
26
- def datetime_frame ():
27
- """
28
- Fixture for DataFrame of floats with DatetimeIndex
29
-
30
- Columns are ['A', 'B', 'C', 'D']
31
-
32
- A B C D
33
- 2000-01-03 -1.122153 0.468535 0.122226 1.693711
34
- 2000-01-04 0.189378 0.486100 0.007864 -1.216052
35
- 2000-01-05 0.041401 -0.835752 -0.035279 -0.414357
36
- 2000-01-06 0.430050 0.894352 0.090719 0.036939
37
- 2000-01-07 -0.620982 -0.668211 -0.706153 1.466335
38
- 2000-01-10 -0.752633 0.328434 -0.815325 0.699674
39
- 2000-01-11 -2.236969 0.615737 -0.829076 -1.196106
40
- ... ... ... ... ...
41
- 2000-02-03 1.642618 -0.579288 0.046005 1.385249
42
- 2000-02-04 -0.544873 -1.160962 -0.284071 -1.418351
43
- 2000-02-07 -2.656149 -0.601387 1.410148 0.444150
44
- 2000-02-08 -1.201881 -1.289040 0.772992 -1.445300
45
- 2000-02-09 1.377373 0.398619 1.008453 -0.928207
46
- 2000-02-10 0.473194 -0.636677 0.984058 0.511519
47
- 2000-02-11 -0.965556 0.408313 -1.312844 -0.381948
48
-
49
- [30 rows x 4 columns]
50
- """
51
- return DataFrame (tm .getTimeSeriesData ())
23
+ def duplicate_columns_frame ():
24
+ """Dataframe with duplicate column names."""
25
+ return DataFrame (np .random .randn (1500 , 4 ), columns = ["a" , "a" , "b" , "b" ])
52
26
53
27
54
28
def test_info_empty ():
@@ -65,9 +39,7 @@ def test_info_empty():
65
39
assert result == expected
66
40
67
41
68
- def test_info_categorical_column ():
69
-
70
- # make sure it works
42
+ def test_info_categorical_column_smoke_test ():
71
43
n = 2500
72
44
df = DataFrame ({"int64" : np .random .randint (100 , size = n )})
73
45
df ["category" ] = Series (
@@ -82,18 +54,48 @@ def test_info_categorical_column():
82
54
df2 .info (buf = buf )
83
55
84
56
85
- def test_info (float_frame , datetime_frame ):
86
- io = StringIO ()
87
- float_frame .info (buf = io )
88
- datetime_frame .info (buf = io )
57
+ @pytest .mark .parametrize (
58
+ "fixture_func_name" ,
59
+ [
60
+ "int_frame" ,
61
+ "float_frame" ,
62
+ "datetime_frame" ,
63
+ "duplicate_columns_frame" ,
64
+ ],
65
+ )
66
+ def test_info_smoke_test (fixture_func_name , request ):
67
+ frame = request .getfixturevalue (fixture_func_name )
68
+ buf = StringIO ()
69
+ frame .info (buf = buf )
70
+ result = buf .getvalue ().splitlines ()
71
+ assert len (result ) > 10
89
72
90
- frame = DataFrame (np .random .randn (5 , 3 ))
91
73
92
- frame .info ()
93
- frame .info (verbose = False )
74
+ @pytest .mark .parametrize (
75
+ "num_columns, max_info_columns, verbose" ,
76
+ [
77
+ (10 , 100 , True ),
78
+ (10 , 11 , True ),
79
+ (10 , 10 , True ),
80
+ (10 , 9 , False ),
81
+ (10 , 1 , False ),
82
+ ],
83
+ )
84
+ def test_info_default_verbose_selection (num_columns , max_info_columns , verbose ):
85
+ frame = DataFrame (np .random .randn (5 , num_columns ))
86
+ with option_context ("display.max_info_columns" , max_info_columns ):
87
+ io_default = StringIO ()
88
+ frame .info (buf = io_default )
89
+ result = io_default .getvalue ()
94
90
91
+ io_explicit = StringIO ()
92
+ frame .info (buf = io_explicit , verbose = verbose )
93
+ expected = io_explicit .getvalue ()
95
94
96
- def test_info_verbose ():
95
+ assert result == expected
96
+
97
+
98
+ def test_info_verbose_check_header_separator_body ():
97
99
buf = StringIO ()
98
100
size = 1001
99
101
start = 5
@@ -202,33 +204,23 @@ def test_info_wide():
202
204
203
205
io = StringIO ()
204
206
df .info (buf = io , max_cols = 101 )
205
- rs = io .getvalue ()
206
- assert len (rs .splitlines ()) > 100
207
- xp = rs
208
-
209
- set_option ("display.max_info_columns" , 101 )
210
- io = StringIO ()
211
- df .info (buf = io )
212
- assert rs == xp
213
- reset_option ("display.max_info_columns" )
214
-
207
+ result = io .getvalue ()
208
+ assert len (result .splitlines ()) > 100
215
209
216
- def test_info_duplicate_columns ():
217
- io = StringIO ()
218
-
219
- # it works!
220
- frame = DataFrame ( np . random . randn ( 1500 , 4 ), columns = [ "a" , "a" , "b" , "b" ] )
221
- frame . info ( buf = io )
210
+ expected = result
211
+ with option_context ( "display.max_info_columns" , 101 ):
212
+ io = StringIO ()
213
+ df . info ( buf = io )
214
+ result = io . getvalue ( )
215
+ assert result == expected
222
216
223
217
224
218
def test_info_duplicate_columns_shows_correct_dtypes ():
225
219
# GH11761
226
220
io = StringIO ()
227
-
228
221
frame = DataFrame ([[1 , 2.0 ]], columns = ["a" , "a" ])
229
222
frame .info (buf = io )
230
- io .seek (0 )
231
- lines = io .readlines ()
223
+ lines = io .getvalue ().splitlines (True )
232
224
assert " 0 a 1 non-null int64 \n " == lines [5 ]
233
225
assert " 1 a 1 non-null float64\n " == lines [6 ]
234
226
@@ -272,7 +264,6 @@ def test_info_max_cols():
272
264
assert len (res .strip ().split ("\n " )) == len_
273
265
274
266
for len_ , verbose in [(12 , None ), (5 , False ), (12 , True )]:
275
-
276
267
# max_cols not exceeded
277
268
with option_context ("max_info_columns" , 5 ):
278
269
buf = StringIO ()
@@ -418,7 +409,6 @@ def test_usage_via_getsizeof():
418
409
419
410
420
411
def test_info_memory_usage_qualified ():
421
-
422
412
buf = StringIO ()
423
413
df = DataFrame (1 , columns = list ("ab" ), index = [1 , 2 , 3 ])
424
414
df .info (buf = buf )
@@ -454,7 +444,8 @@ def memory_usage(f):
454
444
N = 100
455
445
M = len (uppercase )
456
446
index = MultiIndex .from_product (
457
- [list (uppercase ), date_range ("20160101" , periods = N )], names = ["id" , "date" ]
447
+ [list (uppercase ), date_range ("20160101" , periods = N )],
448
+ names = ["id" , "date" ],
458
449
)
459
450
df = DataFrame ({"value" : np .random .randn (N * M )}, index = index )
460
451
0 commit comments