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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 11 additions & 10 deletions
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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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]):

0 commit comments

Comments
 (0)