-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: remove hard dependency on odo
Odo is currently a hard dependency of warp_prism to convert the sqlalchemy types into a numpy dtypes. Odo is no longer actively maintained and breaks with newer versions of pandas. This change reimplements the needed functionality in warp_prism directly without using odo. This PR does leave the odo edge registration code so that existing users don't see a change in functionality.
- Loading branch information
Joe Jevnik
committed
Jan 8, 2020
1 parent
dbd61bf
commit ed0ecf0
Showing
3 changed files
with
202 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import numpy as np | ||
from odo import odo | ||
import pandas as pd | ||
from pandas import read_sql | ||
import perf | ||
|
||
from warp_prism import to_arrays, to_dataframe | ||
from warp_prism.tests import tmp_db_uri | ||
|
||
|
||
def setup(setup): | ||
"""Mark that a test needs a benchmark needs a setup function to prepare the | ||
inputes. | ||
""" | ||
def dec(f): | ||
f._setup = setup | ||
return f | ||
|
||
return dec | ||
|
||
|
||
def setup_largefloat(table_uri): | ||
return odo( | ||
pd.DataFrame({ | ||
'a': np.random.rand(1000000), | ||
'b': np.random.rand(1000000)}, | ||
), | ||
table_uri, | ||
) | ||
|
||
|
||
@setup(setup_largefloat) | ||
def bench_largefloat_warp_prism_to_arrays(table): | ||
counter = perf.perf_counter | ||
start = counter() | ||
_ = to_arrays(table) # noqa | ||
return counter() - start | ||
|
||
|
||
@setup(setup_largefloat) | ||
def bench_largefloat_warp_prism_to_dataframe(table): | ||
counter = perf.perf_counter | ||
start = counter() | ||
_ = to_dataframe(table) # noqa | ||
return counter() - start | ||
|
||
|
||
@setup(setup_largefloat) | ||
def bench_largefloat_odo_to_dataframe(table): | ||
counter = perf.perf_counter | ||
start = counter() | ||
_ = odo(table, pd.DataFrame) # noqa | ||
return counter() - start | ||
|
||
|
||
@setup(setup_largefloat) | ||
def bench_largefloat_pandas_to_dataframe(table): | ||
counter = perf.perf_counter | ||
start = counter() | ||
_ = read_sql(table) # noqa | ||
return counter() - start | ||
|
||
|
||
def main(): | ||
from traceback import print_exc | ||
|
||
def wrapper(wrapped): | ||
def bench(loops, *args): | ||
return wrapped(*args) | ||
|
||
return bench | ||
|
||
with tmp_db_uri() as db_uri: | ||
for k, v in globals().items(): | ||
if k.startswith('bench_'): | ||
runner = perf.Runner() | ||
runner.parse_args() | ||
table_uri = '::'.join((db_uri, k)) | ||
setup = getattr(v, '_setup', lambda table_uri: table_uri) | ||
try: | ||
print('%s: ' % k, end='') | ||
print(runner.bench_sample_func( | ||
k, | ||
wrapper(v), | ||
setup(table_uri), | ||
).format()) | ||
except Exception: | ||
print('%s: error' % k) | ||
print_exc() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |