Repository navigation
Expand file tree
/
Copy pathcompatibility.py
More file actions
145 lines (113 loc) · 3.79 KB
/
Copy pathcompatibility.py
File metadata and controls
145 lines (113 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from __future__ import absolute_import, division, print_function
import sys
from types import MethodType
import pandas.util.testing as tm
from toolz import identity
PY3 = sys.version_info[0] == 3
PY2 = sys.version_info[0] == 2
if PY3:
import builtins
def apply(f, args, **kwargs):
return f(*args, **kwargs)
else:
import __builtin__ as builtins
apply = builtins.apply
try:
import cPickle as pickle
except ImportError:
import pickle
# Portions of this taken from the six library, licensed as follows.
#
# 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.
from toolz.compatibility import map, zip, range, reduce
if PY2:
_inttypes = (int, long)
unicode = builtins.unicode
basestring = builtins.basestring
_strtypes = (str, unicode)
def boundmethod(func, instance):
return MethodType(func, instance, type(instance))
from itertools import izip_longest as zip_longest
from contextlib2 import ExitStack
else:
_inttypes = (int,)
_strtypes = (str,)
unicode = str
basestring = str
boundmethod = MethodType
from itertools import zip_longest
from contextlib import ExitStack
import io
try:
SEEK_END = io.SEEK_END
except AttributeError:
SEEK_END = 2
try:
import pytest
skipif = pytest.mark.skipif
xfail = pytest.mark.xfail
min_python_version = skipif(sys.version_info < (2, 7),
reason="Python >= 2.7 required")
raises = pytest.raises
except ImportError:
# TODO: move the above into a separate testing utils module
pass
if sys.version_info >= (2, 7):
from ctypes import c_ssize_t
else:
import ctypes
if ctypes.sizeof(ctypes.c_void_p) == 4:
c_ssize_t = ctypes.c_int32
else:
c_ssize_t = ctypes.c_int64
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
def assert_series_equal(left, right, check_names=True, **kwargs):
"""Backwards compatibility wrapper for
``pandas.util.testing.assert_series_equal``
Examples
--------
>>> import pandas as pd
>>> s = pd.Series(list('abc'), name='a')
>>> s2 = pd.Series(list('abc'), name='b')
>>> assert_series_equal(s, s2) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: ...
>>> assert_series_equal(s, s2, check_names=False)
See Also
--------
pandas.util.testing.assert_series_equal
"""
try:
return tm.assert_series_equal(left, right, check_names=check_names,
**kwargs)
except TypeError:
if check_names:
assert left.name == right.name
return tm.assert_series_equal(left, right, **kwargs)
if PY2:
def u8(cs):
return cs.decode('utf-8')
else:
u8 = identity