Skip to content

Commit

Permalink
CLN/ENH: Merge compat with py3compat and six
Browse files Browse the repository at this point in the history
For simplicity, move the relevant portions of six into
compat and combine py3compat and compat together (given the distinctions
were relatively arbitrary already). Also switch to importing u to make
things cleaner.
  • Loading branch information
jtratner committed Jul 29, 2013
1 parent 0c0cfbc commit e957fbc
Show file tree
Hide file tree
Showing 161 changed files with 1,237 additions and 1,233 deletions.
21 changes: 21 additions & 0 deletions LICENSES/SIX
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
six license (substantial portions used in the python 3 compatibility module)
===========================================================================
Copyright (c) 2010-2013 Benjamin Peterson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
#
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
#
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion bench/alignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Setup
from pandas.util.py3compat import range, lrange
from pandas.util.compat import range, lrange
import numpy as np
import pandas
import la
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_get_put_value.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pandas import *
from pandas.util.testing import rands
from pandas.util.py3compat import range
from pandas.util.compat import range

N = 1000
K = 50
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_groupby.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pandas import *
from pandas.util.testing import rands
from pandas.util.py3compat import range
from pandas.util.compat import range

import string
import random
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_khash_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from vbench.api import Benchmark
from pandas.util.testing import rands
from pandas.util.py3compat import range
from pandas.util.compat import range
import pandas._tseries as lib
import pandas._sandbox as sbx
import time
Expand Down
12 changes: 4 additions & 8 deletions bench/bench_merge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import random
import gc
import time
from pandas import *
from pandas.util.compat import range, lrange, StringIO
from pandas.util.testing import rands
from pandas.util.py3compat import range, lrange
import random

N = 10000
ngroups = 10
Expand Down Expand Up @@ -29,10 +31,6 @@ def get_test_data(ngroups=100, n=N):
# 'value' : np.random.randn(N // 10)})
# result = merge.merge(df, df2, on='key2')

from collections import defaultdict
import gc
import time
from pandas.util.testing import rands
N = 10000

indices = np.array([rands(10) for _ in range(N)], dtype='O')
Expand Down Expand Up @@ -66,7 +64,6 @@ def get_test_data(ngroups=100, n=N):


# R results
from pandas.util.py3compat import StringIO, lrange
# many to one
r_results = read_table(StringIO(""" base::merge plyr data.table
inner 0.2475 0.1183 0.1100
Expand Down Expand Up @@ -94,7 +91,6 @@ def get_test_data(ngroups=100, n=N):

# many to many

from pandas.util.py3compat import StringIO, lrange
# many to one
r_results = read_table(StringIO("""base::merge plyr data.table
inner 0.4610 0.1276 0.1269
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_merge_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from pandas import DataFrame
from pandas.util.testing import rands
from pandas.util.py3compat import range, zip
from pandas.util.compat import range, zip
import random

N = 10000
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_take_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pandas import DataFrame
import timeit
from pandas.util.py3compat import zip
from pandas.util.compat import zip

setup = """
from pandas import Series
Expand Down
3 changes: 1 addition & 2 deletions bench/bench_unique.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import print_function
from pandas import *
from pandas.util.testing import rands
from pandas.util.py3compat import range
from pandas.util.py3compat import zip
from pandas.util.compat import range, zip
import pandas._tseries as lib
import numpy as np
import matplotlib.pyplot as plt
Expand Down
5 changes: 2 additions & 3 deletions bench/better_unique.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import print_function
from pandas import DataFrame
from pandas.util.py3compat import range
from pandas.util.py3compat import zip
from pandas.util.compat import range, zip
import timeit

setup = """
from pandas import Series
import pandas._tseries as _tseries
from pandas.util.py3compat import range
from pandas.util.compat import range
import random
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion bench/io_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import la
import pandas
from pandas.util.py3compat import range
from pandas.util.compat import range
from pandas import datetools, DateRange


Expand Down
2 changes: 1 addition & 1 deletion bench/serialize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
from pandas.util.py3compat import range, lrange
from pandas.util.compat import range, lrange
import time
import os
import numpy as np
Expand Down
3 changes: 1 addition & 2 deletions bench/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pandas.util.py3compat import range
import numpy as np
import itertools
import collections
import scipy.ndimage as ndi
from pandas.util.py3compat import zip
from pandas.util.compat import zip, range

N = 10000

Expand Down
2 changes: 1 addition & 1 deletion doc/plots/stats/moment_plots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pandas.util.py3compat import range
from pandas.util.compat import range
import numpy as np

import matplotlib.pyplot as plt
Expand Down
10 changes: 5 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import sys
import os
import six
from pandas.util.compat import u

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -64,8 +64,8 @@
master_doc = 'index'

# General information about the project.
project = six.u('pandas')
copyright = six.u('2008-2012, the pandas development team')
project = u('pandas')
copyright = u('2008-2012, the pandas development team')

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -212,8 +212,8 @@
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'pandas.tex',
six.u('pandas: powerful Python data analysis toolkit'),
six.u('Wes McKinney\n\& PyData Development Team'), 'manual'),
u('pandas: powerful Python data analysis toolkit'),
u('Wes McKinney\n\& PyData Development Team'), 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
2 changes: 1 addition & 1 deletion doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ You can even pass in an instance of ``StringIO`` if you so desire

.. ipython:: python
from six.moves import cStringIO as StringIO
from cStringIO import StringIO
with open(file_path, 'r') as f:
sio = StringIO(f.read())
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/comment_eater.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pandas.util.py3compat import cStringIO
from pandas.util.compat import cStringIO
import compiler
import inspect
import textwrap
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/compiler_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

import sys
from pandas.util.py3compat import cStringIO as StringIO
from pandas.util.compat import cStringIO as StringIO
from compiler.ast import Const, Name, Tuple, Div, Mul, Sub, Add

def unparse(ast, single_line_functions=False):
Expand Down
7 changes: 3 additions & 4 deletions doc/sphinxext/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import re
import pydoc
from warnings import warn
from six import StringIO
import six
from pandas.util.compat import StringIO, callable

class Reader(object):
"""A line-based string reader.
Expand Down Expand Up @@ -372,7 +371,7 @@ def _str_index(self):
idx = self['index']
out = []
out += ['.. index:: %s' % idx.get('default','')]
for section, references in six.iteritems(idx):
for section, references in compat.iteritems(idx):
if section == 'default':
continue
out += [' :%s: %s' % (section, ', '.join(references))]
Expand Down Expand Up @@ -491,7 +490,7 @@ def methods(self):
if self._cls is None:
return []
return [name for name,func in inspect.getmembers(self._cls)
if not name.startswith('_') and six.callable(func)]
if not name.startswith('_') and callable(func)]

@property
def properties(self):
Expand Down
6 changes: 3 additions & 3 deletions doc/sphinxext/docscrape_sphinx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re, inspect, textwrap, pydoc
import sphinx
from .docscrape import NumpyDocString, FunctionDoc, ClassDoc
import six
from pandas.util.compat import callable

class SphinxDocString(NumpyDocString):
def __init__(self, docstring, config={}):
Expand Down Expand Up @@ -128,7 +128,7 @@ def _str_index(self):
return out

out += ['.. index:: %s' % idx.get('default','')]
for section, references in six.iteritems(idx):
for section, references in compat.iteritems(idx):
if section == 'default':
continue
elif section == 'refguide':
Expand Down Expand Up @@ -212,7 +212,7 @@ def get_doc_object(obj, what=None, doc=None, config={}):
what = 'class'
elif inspect.ismodule(obj):
what = 'module'
elif six.callable(obj):
elif callable(obj):
what = 'function'
else:
what = 'object'
Expand Down
27 changes: 12 additions & 15 deletions doc/sphinxext/ipython_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
#-----------------------------------------------------------------------------

# Stdlib
from pandas.util.py3compat import range, lmap
from pandas.util.py3compat import map, cStringIO as StringIO
from pandas.util.compat import zip, range, map, lmap, u, cStringIO as StringIO
import ast
import os
import re
Expand All @@ -71,8 +70,6 @@
from docutils.parsers.rst import directives
from docutils import nodes
from sphinx.util.compat import Directive
import six
from pandas.util.py3compat import zip

matplotlib.use('Agg')

Expand Down Expand Up @@ -493,20 +490,20 @@ def process_pure_python(self, content):
multiline = True
cont_len = len(str(lineno)) + 2
line_to_process = line.strip('\\')
output.extend([six.u("%s %s") % (fmtin%lineno,line)])
output.extend([u("%s %s") % (fmtin%lineno,line)])
continue
else: # no we're still not
line_to_process = line.strip('\\')
else: # we are currently on a multiline
line_to_process += line.strip('\\')
if line_stripped.endswith('\\'): # and we still are
continuation = '.' * cont_len
output.extend([(six.u(' %s: ')+line_stripped) % continuation])
output.extend([(u(' %s: ')+line_stripped) % continuation])
continue
# else go ahead and run this multiline then carry on

# get output of line
self.process_input_line(six.text_type(line_to_process.strip()),
self.process_input_line(compat.text_type(line_to_process.strip()),
store_history=False)
out_line = self.cout.getvalue()
self.clear_cout()
Expand All @@ -520,15 +517,15 @@ def process_pure_python(self, content):

# line numbers don't actually matter, they're replaced later
if not multiline:
in_line = six.u("%s %s") % (fmtin%lineno,line)
in_line = u("%s %s") % (fmtin%lineno,line)

output.extend([in_line])
else:
output.extend([(six.u(' %s: ')+line_stripped) % continuation])
output.extend([(u(' %s: ')+line_stripped) % continuation])
multiline = False
if len(out_line):
output.extend([out_line])
output.extend([six.u('')])
output.extend([u('')])

return output

Expand Down Expand Up @@ -570,19 +567,19 @@ def process_pure_python2(self, content):
output.extend([line])
continue

continuation = six.u(' %s:')% ''.join(['.']*(len(str(ct))+2))
continuation = u(' %s:')% ''.join(['.']*(len(str(ct))+2))
if not multiline:
modified = six.u("%s %s") % (fmtin % ct, line_stripped)
modified = u("%s %s") % (fmtin % ct, line_stripped)
output.append(modified)
ct += 1
try:
ast.parse(line_stripped)
output.append(six.u(''))
output.append(u(''))
except Exception:
multiline = True
multiline_start = lineno
else:
modified = six.u('%s %s') % (continuation, line)
modified = u('%s %s') % (continuation, line)
output.append(modified)

try:
Expand All @@ -594,7 +591,7 @@ def process_pure_python2(self, content):

continue

output.extend([continuation, six.u('')])
output.extend([continuation, u('')])
multiline = False
except Exception:
pass
Expand Down
Loading

0 comments on commit e957fbc

Please sign in to comment.