forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpandas_vb_common.py
63 lines (53 loc) · 1.47 KB
/
pandas_vb_common.py
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
import os
from pandas import *
import pandas as pd
from numpy.random import randn
from numpy.random import randint
import pandas.util.testing as tm
import random
import numpy as np
import threading
from importlib import import_module
try:
from pandas.compat import range
except ImportError:
pass
numeric_dtypes = [np.int64, np.int32, np.uint32, np.uint64, np.float32,
np.float64, np.int16, np.int8, np.uint16, np.uint8]
datetime_dtypes = [np.datetime64, np.timedelta64]
# This function just needs to be imported into each benchmark file in order to
# sets up the random seed before each function.
# http://asv.readthedocs.io/en/latest/writing_benchmarks.html
def setup(*args, **kwargs):
np.random.seed(1234)
class BaseIO(object):
"""
Base class for IO benchmarks
"""
fname = None
def remove(self, f):
"""Remove created files"""
try:
os.remove(f)
except:
# On Windows, attempting to remove a file that is in use
# causes an exception to be raised
pass
def teardown(self, *args, **kwargs):
self.remove(self.fname)
# try em until it works!
for imp in ['pandas._libs.lib', 'pandas.lib', 'pandas_tseries']:
try:
lib = import_module(imp)
break
except:
pass
try:
Panel = Panel
except Exception:
Panel = WidePanel
# didn't add to namespace until later
try:
from pandas.core.index import MultiIndex
except ImportError:
pass