Skip to content

Commit 81cfe91

Browse files
Fixed space in small info (pandas-dev#21057)
* Fixed space in small info Closes pandas-dev#21056
1 parent 3be623b commit 81cfe91

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ def _sizeof_fmt(num, size_qualifier):
22312231
# returns size in human readable format
22322232
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
22332233
if num < 1024.0:
2234-
return ("{num:3.1f}{size_q}"
2234+
return ("{num:3.1f}{size_q} "
22352235
"{x}".format(num=num, size_q=size_qualifier, x=x))
22362236
num /= 1024.0
22372237
return "{num:3.1f}{size_q} {pb}".format(num=num,

pandas/tests/frame/test_repr_info.py

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime, timedelta
66
import re
77
import sys
8+
import textwrap
89

910
from numpy import nan
1011
import numpy as np
@@ -204,6 +205,25 @@ def test_info(self):
204205
frame.info()
205206
frame.info(verbose=False)
206207

208+
def test_info_memory(self):
209+
# https://github.com/pandas-dev/pandas/issues/21056
210+
df = pd.DataFrame({'a': pd.Series([1, 2], dtype='i8')})
211+
buf = StringIO()
212+
df.info(buf=buf)
213+
result = buf.getvalue()
214+
bytes = float(df.memory_usage().sum())
215+
216+
expected = textwrap.dedent("""\
217+
<class 'pandas.core.frame.DataFrame'>
218+
RangeIndex: 2 entries, 0 to 1
219+
Data columns (total 1 columns):
220+
a 2 non-null int64
221+
dtypes: int64(1)
222+
memory usage: {} bytes
223+
""".format(bytes))
224+
225+
assert result == expected
226+
207227
def test_info_wide(self):
208228
from pandas import set_option, reset_option
209229
io = StringIO()

0 commit comments

Comments
 (0)