8
8
* lists: lrange(), lmap(), lzip(), lfilter()
9
9
* iterable method compatibility: iteritems, iterkeys, itervalues
10
10
* Uses the original method if available, otherwise uses items, keys, values.
11
- * bind_method: binds functions to classes
12
11
* add_metaclass(metaclass) - class decorator that recreates class with with the
13
12
given metaclass instead (and avoids intermediary class creation)
14
13
22
21
from distutils .version import LooseVersion
23
22
import sys
24
23
import platform
25
- import types
26
24
import struct
27
25
28
26
PY2 = sys .version_info [0 ] == 2
32
30
PY37 = sys .version_info >= (3 , 7 )
33
31
PYPY = platform .python_implementation () == 'PyPy'
34
32
35
- from pandas .compat .chainmap import DeepChainMap
36
-
37
33
38
34
# list-producing versions of the major Python iterating functions
39
35
def lrange (* args , ** kwargs ):
@@ -52,29 +48,6 @@ def lfilter(*args, **kwargs):
52
48
return list (filter (* args , ** kwargs ))
53
49
54
50
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
-
78
51
if PY2 :
79
52
def iteritems (obj , ** kw ):
80
53
return obj .iteritems (** kw )
@@ -95,30 +68,6 @@ def iterkeys(obj, **kw):
95
68
def itervalues (obj , ** kw ):
96
69
return iter (obj .values (** kw ))
97
70
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 )
122
71
# ----------------------------------------------------------------------------
123
72
# functions largely based / taken from the six module
124
73
@@ -133,7 +82,7 @@ def to_str(s):
133
82
Convert bytes and non-string into Python 3 str
134
83
"""
135
84
if isinstance (s , bytes ):
136
- s = bytes_to_str ( s )
85
+ s = s . decode ( 'utf-8' )
137
86
elif not isinstance (s , str ):
138
87
s = str (s )
139
88
return s
@@ -172,6 +121,7 @@ def wrapper(cls):
172
121
return metaclass (cls .__name__ , cls .__bases__ , orig_vars )
173
122
return wrapper
174
123
124
+
175
125
if PY3 :
176
126
def raise_with_traceback (exc , traceback = Ellipsis ):
177
127
if traceback == Ellipsis :
@@ -207,6 +157,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):
207
157
else :
208
158
re_type = type (re .compile ('' ))
209
159
160
+
210
161
# https://github.com/pandas-dev/pandas/pull/9123
211
162
def is_platform_little_endian ():
212
163
""" am I little endian """
0 commit comments