Skip to content

Commit bd1fde4

Browse files
committed
CLN: move pprint_thing to printing
1 parent 2081048 commit bd1fde4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+181
-196
lines changed

ci/lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RET=0
88

99
if [ "$LINT" ]; then
1010
echo "Linting"
11-
for path in 'core' 'indexes' 'types' 'io' 'stats' 'compat' 'sparse' 'tools' 'tseries' 'tests' 'computation' 'util'
11+
for path in 'core' 'indexes' 'types' 'formats' 'io' 'stats' 'compat' 'sparse' 'tools' 'tseries' 'tests' 'computation' 'util'
1212
do
1313
echo "linting -> pandas/$path"
1414
flake8 pandas/$path --filename '*.py'

pandas/computation/engines.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from pandas import compat
99
from pandas.compat import DeepChainMap, map
10-
from pandas.core import common as com
10+
import pandas.core.common as com
11+
import pandas.formats.printing as printing
1112
from pandas.computation.align import _align, _reconstruct_object
1213
from pandas.computation.ops import (UndefinedVariableError,
1314
_mathops, _reductions)
@@ -55,7 +56,7 @@ def convert(self):
5556
5657
Defaults to return the expression as a string.
5758
"""
58-
return com.pprint_thing(self.expr)
59+
return printing.pprint_thing(self.expr)
5960

6061
def evaluate(self):
6162
"""Run the engine on the expression

pandas/computation/eval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import warnings
77
import tokenize
8-
from pandas.core import common as com
8+
from pandas.formats.printing import pprint_thing
99
from pandas.computation import _NUMEXPR_INSTALLED
1010
from pandas.computation.expr import Expr, _parsers, tokenize_string
1111
from pandas.computation.scope import _ensure_scope
@@ -108,7 +108,7 @@ def _convert_expression(expr):
108108
ValueError
109109
* If the expression is empty.
110110
"""
111-
s = com.pprint_thing(expr)
111+
s = pprint_thing(expr)
112112
_check_expression(s)
113113
return s
114114

pandas/computation/expr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.compat import StringIO, lmap, zip, reduce, string_types
1212
from pandas.core.base import StringMixin
1313
from pandas.core import common as com
14+
import pandas.formats.printing as printing
1415
from pandas.tools.util import compose
1516
from pandas.computation.ops import (_cmp_ops_syms, _bool_ops_syms,
1617
_arith_ops_syms, _unary_ops_syms, is_term)
@@ -716,7 +717,7 @@ def __call__(self):
716717
return self.terms(self.env)
717718

718719
def __unicode__(self):
719-
return com.pprint_thing(self.terms)
720+
return printing.pprint_thing(self.terms)
720721

721722
def __len__(self):
722723
return len(self.expr)

pandas/computation/ops.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pandas as pd
1111
from pandas.compat import PY3, string_types, text_type
1212
import pandas.core.common as com
13+
from pandas.formats.printing import pprint_thing, pprint_thing_encoded
1314
import pandas.lib as lib
1415
from pandas.core.base import StringMixin
1516
from pandas.computation.common import _ensure_decoded, _result_type_many
@@ -62,7 +63,7 @@ def local_name(self):
6263
return self.name.replace(_LOCAL_TAG, '')
6364

6465
def __unicode__(self):
65-
return com.pprint_thing(self.name)
66+
return pprint_thing(self.name)
6667

6768
def __call__(self, *args, **kwargs):
6869
return self.value
@@ -118,9 +119,9 @@ def type(self):
118119

119120
@property
120121
def raw(self):
121-
return com.pprint_thing('{0}(name={1!r}, type={2})'
122-
''.format(self.__class__.__name__, self.name,
123-
self.type))
122+
return pprint_thing('{0}(name={1!r}, type={2})'
123+
''.format(self.__class__.__name__, self.name,
124+
self.type))
124125

125126
@property
126127
def is_datetime(self):
@@ -186,9 +187,9 @@ def __unicode__(self):
186187
"""Print a generic n-ary operator and its operands using infix
187188
notation"""
188189
# recurse over the operands
189-
parened = ('({0})'.format(com.pprint_thing(opr))
190+
parened = ('({0})'.format(pprint_thing(opr))
190191
for opr in self.operands)
191-
return com.pprint_thing(' {0} '.format(self.op).join(parened))
192+
return pprint_thing(' {0} '.format(self.op).join(parened))
192193

193194
@property
194195
def return_type(self):
@@ -390,10 +391,10 @@ def convert_values(self):
390391
"""
391392
def stringify(value):
392393
if self.encoding is not None:
393-
encoder = partial(com.pprint_thing_encoded,
394+
encoder = partial(pprint_thing_encoded,
394395
encoding=self.encoding)
395396
else:
396-
encoder = com.pprint_thing
397+
encoder = pprint_thing
397398
return encoder(value)
398399

399400
lhs, rhs = self.lhs, self.rhs
@@ -491,7 +492,7 @@ def __call__(self, env):
491492
return self.func(operand)
492493

493494
def __unicode__(self):
494-
return com.pprint_thing('{0}({1})'.format(self.op, self.operand))
495+
return pprint_thing('{0}({1})'.format(self.op, self.operand))
495496

496497
@property
497498
def return_type(self):
@@ -516,7 +517,7 @@ def __call__(self, env):
516517

517518
def __unicode__(self):
518519
operands = map(str, self.operands)
519-
return com.pprint_thing('{0}({1})'.format(self.op, ','.join(operands)))
520+
return pprint_thing('{0}({1})'.format(self.op, ','.join(operands)))
520521

521522

522523
class FuncNode(object):

pandas/computation/pytables.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from datetime import datetime, timedelta
88
import numpy as np
99
import pandas as pd
10+
import pandas.core.common as com
1011
from pandas.compat import u, string_types, DeepChainMap
1112
from pandas.core.base import StringMixin
12-
import pandas.core.common as com
13+
from pandas.formats.printing import pprint_thing, pprint_thing_encoded
1314
from pandas.computation import expr, ops
1415
from pandas.computation.ops import is_term, UndefinedVariableError
1516
from pandas.computation.expr import BaseExprVisitor
@@ -169,10 +170,10 @@ def convert_value(self, v):
169170

170171
def stringify(value):
171172
if self.encoding is not None:
172-
encoder = partial(com.pprint_thing_encoded,
173+
encoder = partial(pprint_thing_encoded,
173174
encoding=self.encoding)
174175
else:
175-
encoder = com.pprint_thing
176+
encoder = pprint_thing
176177
return encoder(value)
177178

178179
kind = _ensure_decoded(self.kind)
@@ -224,8 +225,8 @@ def convert_values(self):
224225
class FilterBinOp(BinOp):
225226

226227
def __unicode__(self):
227-
return com.pprint_thing("[Filter : [{0}] -> "
228-
"[{1}]".format(self.filter[0], self.filter[1]))
228+
return pprint_thing("[Filter : [{0}] -> "
229+
"[{1}]".format(self.filter[0], self.filter[1]))
229230

230231
def invert(self):
231232
""" invert the filter """
@@ -296,7 +297,7 @@ def evaluate(self):
296297
class ConditionBinOp(BinOp):
297298

298299
def __unicode__(self):
299-
return com.pprint_thing("[Condition : [{0}]]".format(self.condition))
300+
return pprint_thing("[Condition : [{0}]]".format(self.condition))
300301

301302
def invert(self):
302303
""" invert the condition """
@@ -571,8 +572,8 @@ def convert(v):
571572

572573
def __unicode__(self):
573574
if self.terms is not None:
574-
return com.pprint_thing(self.terms)
575-
return com.pprint_thing(self.expr)
575+
return pprint_thing(self.terms)
576+
return pprint_thing(self.expr)
576577

577578
def evaluate(self):
578579
""" create and return the numexpr condition and filter """

pandas/core/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pandas.util.decorators import (Appender, cache_readonly,
1111
deprecate_kwarg, Substitution)
1212
from pandas.core.common import AbstractMethodError
13+
from pandas.formats.printing import pprint_thing
1314

1415
_shared_docs = dict()
1516
_indexops_doc_kwargs = dict(klass='IndexOpsMixin', inplace='',
@@ -680,7 +681,6 @@ def _disabled(self, *args, **kwargs):
680681
self.__class__.__name__)
681682

682683
def __unicode__(self):
683-
from pandas.core.common import pprint_thing
684684
return pprint_thing(self, quote_strings=True,
685685
escape_chars=('\t', '\r', '\n'))
686686

@@ -724,8 +724,8 @@ def __unicode__(self):
724724
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
725725
py2/py3.
726726
"""
727-
prepr = com.pprint_thing(self, escape_chars=('\t', '\r', '\n'),
728-
quote_strings=True)
727+
prepr = pprint_thing(self, escape_chars=('\t', '\r', '\n'),
728+
quote_strings=True)
729729
return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype)
730730

731731

pandas/core/categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ def _repr_categories(self):
14331433
""" return the base repr for the categories """
14341434
max_categories = (10 if get_option("display.max_categories") == 0 else
14351435
get_option("display.max_categories"))
1436-
from pandas.core import format as fmt
1436+
from pandas.formats import format as fmt
14371437
if len(self.categories) > max_categories:
14381438
num = max_categories // 2
14391439
head = fmt.format_array(self.categories[:num], None)
@@ -1481,7 +1481,7 @@ def _repr_footer(self):
14811481
return u('Length: %d\n%s') % (len(self), self._repr_categories_info())
14821482

14831483
def _get_repr(self, length=True, na_rep='NaN', footer=True):
1484-
from pandas.core import format as fmt
1484+
from pandas.formats import format as fmt
14851485
formatter = fmt.CategoricalFormatter(self, length=length,
14861486
na_rep=na_rep, footer=footer)
14871487
result = formatter.to_string()

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pandas.lib as lib
1515
import pandas.tslib as tslib
1616
from pandas import compat
17-
from pandas.compat import (range, long, u, zip, map, string_types,
17+
from pandas.compat import (long, zip, map, string_types,
1818
iteritems)
1919
from pandas.types import api as gt
2020
from pandas.types.api import * # noqa

pandas/core/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def is_instance_factory(_type):
773773
"""
774774
if isinstance(_type, (tuple, list)):
775775
_type = tuple(_type)
776-
from pandas.core.common import pprint_thing
776+
from pandas.formats.printing import pprint_thing
777777
type_repr = "|".join(map(pprint_thing, _type))
778778
else:
779779
type_repr = "'%s'" % _type
@@ -791,7 +791,7 @@ def is_one_of_factory(legal_values):
791791
legal_values = [c for c in legal_values if not callable(c)]
792792

793793
def inner(x):
794-
from pandas.core.common import pprint_thing as pp
794+
from pandas.formats.printing import pprint_thing as pp
795795
if x not in legal_values:
796796

797797
if not any([c(x) for c in callables]):

pandas/core/frame.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import pandas.core.nanops as nanops
5858
import pandas.core.ops as ops
5959
import pandas.formats.format as fmt
60+
from pandas.formats.printing import pprint_thing
6061
import pandas.tools.plotting as gfx
6162

6263
import pandas.lib as lib
@@ -1668,7 +1669,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
16681669
def _verbose_repr():
16691670
lines.append('Data columns (total %d columns):' %
16701671
len(self.columns))
1671-
space = max([len(com.pprint_thing(k)) for k in self.columns]) + 4
1672+
space = max([len(pprint_thing(k)) for k in self.columns]) + 4
16721673
counts = None
16731674

16741675
tmpl = "%s%s"
@@ -1682,7 +1683,7 @@ def _verbose_repr():
16821683
dtypes = self.dtypes
16831684
for i, col in enumerate(self.columns):
16841685
dtype = dtypes.iloc[i]
1685-
col = com.pprint_thing(col)
1686+
col = pprint_thing(col)
16861687

16871688
count = ""
16881689
if show_counts:
@@ -4145,7 +4146,7 @@ def _apply_standard(self, func, axis, ignore_failures=False, reduce=True):
41454146
if i is not None:
41464147
k = res_index[i]
41474148
e.args = e.args + ('occurred at index %s' %
4148-
com.pprint_thing(k), )
4149+
pprint_thing(k), )
41494150
raise
41504151

41514152
if len(results) > 0 and is_sequence(results[0]):

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pandas.core.common as com
2020
import pandas.core.missing as missing
2121
import pandas.core.datetools as datetools
22+
from pandas.formats.printing import pprint_thing
2223
from pandas import compat
2324
from pandas.compat import (map, zip, lrange, string_types,
2425
isidentifier, set_function_name)
@@ -150,7 +151,7 @@ def _constructor(self):
150151
def __unicode__(self):
151152
# unicode representation based upon iterating over self
152153
# (since, by definition, `PandasContainers` are iterable)
153-
prepr = '[%s]' % ','.join(map(com.pprint_thing, self))
154+
prepr = '[%s]' % ','.join(map(pprint_thing, self))
154155
return '%s(%s)' % (self.__class__.__name__, prepr)
155156

156157
def _dir_additions(self):

pandas/core/groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pandas.core.panel import Panel
2525
from pandas.util.decorators import (cache_readonly, Substitution, Appender,
2626
make_signature, deprecate_kwarg)
27+
from pandas.formats.printing import pprint_thing
2728
import pandas.core.algorithms as algos
2829
import pandas.core.common as com
2930
from pandas.core.common import(_possibly_downcast_to_dtype, isnull,
@@ -2213,7 +2214,7 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None,
22132214
len(self.grouper) == len(self.index)):
22142215
errmsg = ('Grouper result violates len(labels) == '
22152216
'len(data)\nresult: %s' %
2216-
com.pprint_thing(self.grouper))
2217+
pprint_thing(self.grouper))
22172218
self.grouper = None # Try for sanity
22182219
raise AssertionError(errmsg)
22192220

pandas/core/internals.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from pandas.core.indexing import maybe_convert_indices, length_of_indexer
2828
from pandas.core.categorical import Categorical, maybe_to_categorical
2929
from pandas.tseries.index import DatetimeIndex
30+
from pandas.formats.printing import pprint_thing
3031
import pandas.core.common as com
3132
import pandas.core.missing as missing
3233
import pandas.core.convert as convert
@@ -195,15 +196,15 @@ def mgr_locs(self, new_mgr_locs):
195196
def __unicode__(self):
196197

197198
# don't want to print out all of the items here
198-
name = com.pprint_thing(self.__class__.__name__)
199+
name = pprint_thing(self.__class__.__name__)
199200
if self._is_single_block:
200201

201202
result = '%s: %s dtype: %s' % (name, len(self), self.dtype)
202203

203204
else:
204205

205-
shape = ' x '.join([com.pprint_thing(s) for s in self.shape])
206-
result = '%s: %s, %s, dtype: %s' % (name, com.pprint_thing(
206+
shape = ' x '.join([pprint_thing(s) for s in self.shape])
207+
result = '%s: %s, %s, dtype: %s' % (name, pprint_thing(
207208
self.mgr_locs.indexer), shape, self.dtype)
208209

209210
return result
@@ -2783,15 +2784,15 @@ def __len__(self):
27832784
return len(self.items)
27842785

27852786
def __unicode__(self):
2786-
output = com.pprint_thing(self.__class__.__name__)
2787+
output = pprint_thing(self.__class__.__name__)
27872788
for i, ax in enumerate(self.axes):
27882789
if i == 0:
27892790
output += u('\nItems: %s') % ax
27902791
else:
27912792
output += u('\nAxis %d: %s') % (i, ax)
27922793

27932794
for block in self.blocks:
2794-
output += u('\n%s') % com.pprint_thing(block)
2795+
output += u('\n%s') % pprint_thing(block)
27952796
return output
27962797

27972798
def _verify_integrity(self):

pandas/core/panel.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from pandas.core.generic import NDFrame, _shared_docs
2323
from pandas.core.index import (Index, MultiIndex, _ensure_index,
2424
_get_combined_index)
25+
from pandas.formats.printing import pprint_thing
2526
from pandas.core.indexing import maybe_droplevels
2627
from pandas.core.internals import (BlockManager,
2728
create_block_manager_from_arrays,
@@ -345,8 +346,8 @@ def axis_pretty(a):
345346
v = getattr(self, a)
346347
if len(v) > 0:
347348
return u('%s axis: %s to %s') % (a.capitalize(),
348-
com.pprint_thing(v[0]),
349-
com.pprint_thing(v[-1]))
349+
pprint_thing(v[0]),
350+
pprint_thing(v[-1]))
350351
else:
351352
return u('%s axis: None') % a.capitalize()
352353

0 commit comments

Comments
 (0)