Skip to content

Commit 6451eb5

Browse files
committed
Removing io.formats.common and moving functions to formats.format
1 parent 196220b commit 6451eb5

File tree

5 files changed

+60
-66
lines changed

5 files changed

+60
-66
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
18421842
- If False, never show counts.
18431843
18441844
"""
1845-
from pandas.io.formats.common import buffer_put_lines
1845+
from pandas.io.formats.format import buffer_put_lines
18461846

18471847
if buf is None: # pragma: no cover
18481848
buf = sys.stdout

pandas/io/formats/common.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

pandas/io/formats/excel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.core.dtypes.common import is_float, is_scalar
1515
from pandas.core.dtypes import missing
1616
from pandas import Index, MultiIndex, PeriodIndex
17-
from pandas.io.formats.common import get_level_lengths
17+
from pandas.io.formats.format import get_level_lengths
1818

1919

2020
class ExcelCell(object):

pandas/io/formats/format.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,3 +1543,59 @@ def _binify(cols, line_width):
15431543

15441544
bins.append(len(cols))
15451545
return bins
1546+
1547+
1548+
def get_level_lengths(levels, sentinel=''):
1549+
"""For each index in each level the function returns lengths of indexes.
1550+
1551+
Parameters
1552+
----------
1553+
levels : list of lists
1554+
List of values on for level.
1555+
sentinel : string, optional
1556+
Value which states that no new index starts on there.
1557+
1558+
Returns
1559+
----------
1560+
Returns list of maps. For each level returns map of indexes (key is index
1561+
in row and value is length of index).
1562+
"""
1563+
if len(levels) == 0:
1564+
return []
1565+
1566+
control = [True for x in levels[0]]
1567+
1568+
result = []
1569+
for level in levels:
1570+
last_index = 0
1571+
1572+
lengths = {}
1573+
for i, key in enumerate(level):
1574+
if control[i] and key == sentinel:
1575+
pass
1576+
else:
1577+
control[i] = False
1578+
lengths[last_index] = i - last_index
1579+
last_index = i
1580+
1581+
lengths[last_index] = len(level) - last_index
1582+
1583+
result.append(lengths)
1584+
1585+
return result
1586+
1587+
1588+
def buffer_put_lines(buf, lines):
1589+
"""
1590+
Appends lines to a buffer.
1591+
1592+
Parameters
1593+
----------
1594+
buf
1595+
The buffer to write to
1596+
lines
1597+
The lines to append.
1598+
"""
1599+
if any(isinstance(x, compat.text_type) for x in lines):
1600+
lines = [compat.text_type(x) for x in lines]
1601+
buf.write('\n'.join(lines))

pandas/io/formats/html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
OrderedDict, unichr)
1616
from pandas.core.config import get_option
1717
from pandas.io.formats.printing import pprint_thing
18-
from pandas.io.formats.common import (
19-
get_level_lengths, buffer_put_lines)
18+
from pandas.io.formats.format import (get_level_lengths,
19+
buffer_put_lines)
2020
from pandas.io.formats.format import TableFormatter
2121

2222

0 commit comments

Comments
 (0)