-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: ASV io benchmarks #18906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
CLN: ASV io benchmarks #18906
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
import numpy as np | ||
from pandas import DataFrame, date_range, ExcelWriter, read_excel | ||
from pandas.compat import BytesIO | ||
import pandas.util.testing as tm | ||
|
||
from ..pandas_vb_common import BaseIO, setup # noqa | ||
|
||
|
||
class Excel(object): | ||
|
||
goal_time = 0.2 | ||
params = ['openpyxl', 'xlsxwriter', 'xlwt'] | ||
param_names = ['engine'] | ||
|
||
def setup(self, engine): | ||
N = 2000 | ||
C = 5 | ||
self.df = DataFrame(np.random.randn(N, C), | ||
columns=['float{}'.format(i) for i in range(C)], | ||
index=date_range('20000101', periods=N, freq='H')) | ||
self.df['object'] = tm.makeStringIndex(N) | ||
self.bio_read = BytesIO() | ||
self.writer_read = ExcelWriter(self.bio_read, engine=engine) | ||
self.df.to_excel(self.writer_read, sheet_name='Sheet1') | ||
self.writer_read.save() | ||
self.bio_read.seek(0) | ||
|
||
self.bio_write = BytesIO() | ||
self.bio_write.seek(0) | ||
self.writer_write = ExcelWriter(self.bio_write, engine=engine) | ||
|
||
def time_read_excel(self, engine): | ||
read_excel(self.bio_read) | ||
|
||
def time_write_excel(self, engine): | ||
self.df.to_excel(self.writer_write, sheet_name='Sheet1') | ||
self.writer_write.save() |
This file contains hidden or 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 hidden or 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,26 @@ | ||
import numpy as np | ||
from pandas import DataFrame, date_range, read_msgpack | ||
import pandas.util.testing as tm | ||
|
||
from ..pandas_vb_common import BaseIO, setup # noqa | ||
|
||
|
||
class MSGPack(BaseIO): | ||
|
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.fname = '__test__.msg' | ||
N = 100000 | ||
C = 5 | ||
self.df = DataFrame(np.random.randn(N, C), | ||
columns=['float{}'.format(i) for i in range(C)], | ||
index=date_range('20000101', periods=N, freq='H')) | ||
self.df['object'] = tm.makeStringIndex(N) | ||
self.df.to_msgpack(self.fname) | ||
|
||
def time_read_msgpack(self): | ||
read_msgpack(self.fname) | ||
|
||
def time_write_msgpack(self): | ||
self.df.to_msgpack(self.fname) |
This file contains hidden or 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,26 @@ | ||
import numpy as np | ||
from pandas import DataFrame, date_range, read_pickle | ||
import pandas.util.testing as tm | ||
|
||
from ..pandas_vb_common import BaseIO, setup # noqa | ||
|
||
|
||
class Pickle(BaseIO): | ||
|
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.fname = '__test__.pkl' | ||
N = 100000 | ||
C = 5 | ||
self.df = DataFrame(np.random.randn(N, C), | ||
columns=['float{}'.format(i) for i in range(C)], | ||
index=date_range('20000101', periods=N, freq='H')) | ||
self.df['object'] = tm.makeStringIndex(N) | ||
self.df.to_pickle(self.fname) | ||
|
||
def time_read_pickle(self): | ||
read_pickle(self.fname) | ||
|
||
def time_write_pickle(self): | ||
self.df.to_pickle(self.fname) |
This file contains hidden or 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,21 @@ | ||
import os | ||
|
||
from pandas import read_sas | ||
|
||
|
||
class SAS(object): | ||
|
||
goal_time = 0.2 | ||
params = ['sas7bdat', 'xport'] | ||
param_names = ['format'] | ||
|
||
def setup(self, format): | ||
# Read files that are located in 'pandas/io/tests/sas/data' | ||
files = {'sas7bdat': 'test1.sas7bdat', 'xport': 'paxraw_d_short.xpt'} | ||
file = files[format] | ||
paths = [os.path.dirname(__file__), '..', '..', '..', 'pandas', | ||
'tests', 'io', 'sas', 'data', file] | ||
self.f = os.path.join(*paths) | ||
|
||
def time_read_msgpack(self, format): | ||
read_sas(self.f, format=format) |
This file contains hidden or 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,84 @@ | ||
import sqlite3 | ||
|
||
import numpy as np | ||
import pandas.util.testing as tm | ||
from pandas import DataFrame, date_range, read_sql_query, read_sql_table | ||
from sqlalchemy import create_engine | ||
|
||
from ..pandas_vb_common import setup # noqa | ||
|
||
|
||
class SQL(object): | ||
|
||
goal_time = 0.2 | ||
params = (['sqlalchemy', 'sqlite'], | ||
['float', 'float_with_nan', 'string', 'bool', 'int', 'datetime']) | ||
param_names = ['connection', 'dtype'] | ||
|
||
def setup(self, connection, dtype): | ||
N = 10000 | ||
con = {'sqlalchemy': create_engine('sqlite:///:memory:'), | ||
'sqlite': sqlite3.connect(':memory:')} | ||
self.table_name = 'test_type' | ||
self.query_all = 'SELECT * FROM {}'.format(self.table_name) | ||
self.query_col = 'SELECT {} FROM {}'.format(dtype, self.table_name) | ||
self.con = con[connection] | ||
self.df = DataFrame({'float': np.random.randn(N), | ||
'float_with_nan': np.random.randn(N), | ||
'string': ['foo'] * N, | ||
'bool': [True] * N, | ||
'int': np.random.randint(0, N, size=N), | ||
'datetime': date_range('2000-01-01', | ||
periods=N, | ||
freq='s')}, | ||
index=tm.makeStringIndex(N)) | ||
self.df.loc[1000:3000, 'float_with_nan'] = np.nan | ||
self.df['datetime_string'] = self.df['datetime'].astype(str) | ||
self.df.to_sql(self.table_name, self.con, if_exists='replace') | ||
|
||
def time_to_sql_dataframe_full(self, connection, dtype): | ||
self.df.to_sql('test1', self.con, if_exists='replace') | ||
|
||
def time_to_sql_dataframe_colums(self, connection, dtype): | ||
self.df[[dtype]].to_sql('test1', self.con, if_exists='replace') | ||
|
||
def time_read_sql_query_select_all(self, connection, dtype): | ||
read_sql_query(self.query_all, self.con) | ||
|
||
def time_read_sql_query_select_column(self, connection, dtype): | ||
read_sql_query(self.query_all, self.con) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. query_col ? |
||
|
||
|
||
class ReadSQLTable(object): | ||
|
||
goal_time = 0.2 | ||
|
||
params = ['float', 'float_with_nan', 'string', 'bool', 'int', 'datetime'] | ||
param_names = ['dtype'] | ||
|
||
def setup(self, dtype): | ||
N = 10000 | ||
self.table_name = 'test' | ||
self.con = create_engine('sqlite:///:memory:') | ||
self.df = DataFrame({'float': np.random.randn(N), | ||
'float_with_nan': np.random.randn(N), | ||
'string': ['foo'] * N, | ||
'bool': [True] * N, | ||
'int': np.random.randint(0, N, size=N), | ||
'datetime': date_range('2000-01-01', | ||
periods=N, | ||
freq='s')}, | ||
index=tm.makeStringIndex(N)) | ||
self.df.loc[1000:3000, 'float_with_nan'] = np.nan | ||
self.df['datetime_string'] = self.df['datetime'].astype(str) | ||
self.df.to_sql(self.table_name, self.con, if_exists='replace') | ||
|
||
def time_read_sql_table_all(self, dtype): | ||
read_sql_table(self.table_name, self.con) | ||
|
||
def time_read_sql_table_column(self, dtype): | ||
read_sql_table(self.table_name, self.con, columns=[dtype]) | ||
|
||
def time_read_sql_table_parse_dates(self, dtype): | ||
read_sql_table(self.table_name, self.con, columns=['datetime_string'], | ||
parse_dates=['datetime_string']) |
This file contains hidden or 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,37 @@ | ||
import numpy as np | ||
from pandas import DataFrame, date_range, read_stata | ||
import pandas.util.testing as tm | ||
|
||
from ..pandas_vb_common import BaseIO, setup # noqa | ||
|
||
|
||
class Stata(BaseIO): | ||
|
||
goal_time = 0.2 | ||
params = ['tc', 'td', 'tm', 'tw', 'th', 'tq', 'ty'] | ||
param_names = ['convert_dates'] | ||
|
||
def setup(self, convert_dates): | ||
self.fname = '__test__.dta' | ||
N = 100000 | ||
C = 5 | ||
self.df = DataFrame(np.random.randn(N, C), | ||
columns=['float{}'.format(i) for i in range(C)], | ||
index=date_range('20000101', periods=N, freq='H')) | ||
self.df['object'] = tm.makeStringIndex(N) | ||
self.df['int8_'] = np.random.randint(np.iinfo(np.int8).min, | ||
np.iinfo(np.int8).max - 27, N) | ||
self.df['int16_'] = np.random.randint(np.iinfo(np.int16).min, | ||
np.iinfo(np.int16).max - 27, N) | ||
self.df['int32_'] = np.random.randint(np.iinfo(np.int32).min, | ||
np.iinfo(np.int32).max - 27, N) | ||
self.df['float32_'] = np.array(np.random.randn(N), | ||
dtype=np.float32) | ||
self.convert_dates = {'index': convert_dates} | ||
self.df.to_stata(self.fname, self.convert_dates) | ||
|
||
def time_read_stata(self, convert_dates): | ||
read_stata(self.fname) | ||
|
||
def time_write_stata(self, convert_dates): | ||
self.df.to_stata(self.fname, self.convert_dates) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally keep this benchmark splitted into two classes where one has those params (for testing types) and the other not. As now this creates a lot of extra benchmarks that are not needed