88* lists: lrange(), lmap(), lzip(), lfilter()
99* iterable method compatibility: iteritems, iterkeys, itervalues
1010 * Uses the original method if available, otherwise uses items, keys, values.
11- * bind_method: binds functions to classes
1211* add_metaclass(metaclass) - class decorator that recreates class with with the
1312 given metaclass instead (and avoids intermediary class creation)
1413
2221from distutils .version import LooseVersion
2322import sys
2423import platform
25- import types
2624import struct
2725
2826PY2 = sys .version_info [0 ] == 2
3230PY37 = sys .version_info >= (3 , 7 )
3331PYPY = platform .python_implementation () == 'PyPy'
3432
35- from pandas .compat .chainmap import DeepChainMap
36-
3733
3834# list-producing versions of the major Python iterating functions
3935def lrange (* args , ** kwargs ):
@@ -52,29 +48,6 @@ def lfilter(*args, **kwargs):
5248 return list (filter (* args , ** kwargs ))
5349
5450
55- if PY3 :
56- def isidentifier (s ):
57- return s .isidentifier ()
58-
59- def str_to_bytes (s , encoding = None ):
60- return s .encode (encoding or 'ascii' )
61-
62- def bytes_to_str (b , encoding = None ):
63- return b .decode (encoding or 'utf-8' )
64-
65- else :
66- # Python 2
67- _name_re = re .compile (r"[a-zA-Z_][a-zA-Z0-9_]*$" )
68-
69- def isidentifier (s , dotted = False ):
70- return bool (_name_re .match (s ))
71-
72- def str_to_bytes (s , encoding = 'ascii' ):
73- return s
74-
75- def bytes_to_str (b , encoding = 'ascii' ):
76- return b
77-
7851if PY2 :
7952 def iteritems (obj , ** kw ):
8053 return obj .iteritems (** kw )
@@ -95,30 +68,6 @@ def iterkeys(obj, **kw):
9568 def itervalues (obj , ** kw ):
9669 return iter (obj .values (** kw ))
9770
98-
99- def bind_method (cls , name , func ):
100- """Bind a method to class, python 2 and python 3 compatible.
101-
102- Parameters
103- ----------
104-
105- cls : type
106- class to receive bound method
107- name : basestring
108- name of method on class instance
109- func : function
110- function to be bound as method
111-
112-
113- Returns
114- -------
115- None
116- """
117- # only python 2 has bound/unbound method issue
118- if not PY3 :
119- setattr (cls , name , types .MethodType (func , None , cls ))
120- else :
121- setattr (cls , name , func )
12271# ----------------------------------------------------------------------------
12372# functions largely based / taken from the six module
12473
@@ -133,7 +82,7 @@ def to_str(s):
13382 Convert bytes and non-string into Python 3 str
13483 """
13584 if isinstance (s , bytes ):
136- s = bytes_to_str ( s )
85+ s = s . decode ( 'utf-8' )
13786 elif not isinstance (s , str ):
13887 s = str (s )
13988 return s
@@ -172,6 +121,7 @@ def wrapper(cls):
172121 return metaclass (cls .__name__ , cls .__bases__ , orig_vars )
173122 return wrapper
174123
124+
175125if PY3 :
176126 def raise_with_traceback (exc , traceback = Ellipsis ):
177127 if traceback == Ellipsis :
@@ -207,6 +157,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):
207157else :
208158 re_type = type (re .compile ('' ))
209159
160+
210161# https://github.com/pandas-dev/pandas/pull/9123
211162def is_platform_little_endian ():
212163 """ am I little endian """
0 commit comments