-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ASV/CLN: cleanup period benchmarks #18275
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
Changes from 2 commits
010e80d
b6551f7
41ec6e0
4c8e8e2
e19d397
27d75c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,84 +3,11 @@ | |
|
||
|
||
class PeriodProperties(object): | ||
def setup(self): | ||
self.per = Period('2012-06-01', freq='M') | ||
|
||
def time_year(self): | ||
self.per.year | ||
|
||
def time_month(self): | ||
self.per.month | ||
|
||
def time_quarter(self): | ||
self.per.quarter | ||
params = ['M', 'min'] | ||
param_names = ['freq'] | ||
|
||
def time_day(self): | ||
self.per.day | ||
|
||
def time_hour(self): | ||
self.per.hour | ||
|
||
def time_minute(self): | ||
self.per.second | ||
|
||
def time_second(self): | ||
self.per.second | ||
|
||
def time_leap_year(self): | ||
self.per.is_leapyear | ||
|
||
|
||
class Constructor(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.rng = date_range('1985', periods=1000) | ||
self.rng2 = date_range('1985', periods=1000).to_pydatetime() | ||
|
||
def time_from_date_range(self): | ||
PeriodIndex(self.rng, freq='D') | ||
|
||
def time_from_pydatetime(self): | ||
PeriodIndex(self.rng2, freq='D') | ||
|
||
|
||
class DataFrame(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.rng = pd.period_range(start='1/1/1990', freq='S', periods=20000) | ||
self.df = pd.DataFrame(index=range(len(self.rng))) | ||
|
||
def time_setitem_period_column(self): | ||
self.df['col'] = self.rng | ||
|
||
|
||
class Algorithms(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
data = [Period('2011-01', freq='M'), Period('2011-02', freq='M'), | ||
Period('2011-03', freq='M'), Period('2011-04', freq='M')] | ||
self.s = Series(data * 1000) | ||
self.i = PeriodIndex(data, freq='M') | ||
|
||
def time_drop_duplicates_pseries(self): | ||
self.s.drop_duplicates() | ||
|
||
def time_drop_duplicates_pindex(self): | ||
self.i.drop_duplicates() | ||
|
||
def time_value_counts_pseries(self): | ||
self.s.value_counts() | ||
|
||
def time_value_counts_pindex(self): | ||
self.i.value_counts() | ||
|
||
|
||
class Properties(object): | ||
def setup(self): | ||
self.per = Period('2017-09-06 08:28', freq='min') | ||
def setup(self, freq): | ||
self.per = Period('2012-06-01', freq=freq) | ||
|
||
def time_year(self): | ||
self.per.year | ||
|
@@ -101,7 +28,7 @@ def time_second(self): | |
self.per.second | ||
|
||
def time_is_leap_year(self): | ||
self.per.is_leap_year | ||
self.per.is_leapyear | ||
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. I think 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. Yep, you're right. One of the two existing benchmarks used each and I guessed wrong. |
||
|
||
def time_quarter(self): | ||
self.per.quarter | ||
|
@@ -137,7 +64,68 @@ def time_asfreq(): | |
self.per.asfreq('A') | ||
|
||
|
||
class period_standard_indexing(object): | ||
class PeriodIndexConstructor(object): | ||
goal_time = 0.2 | ||
|
||
params = ['D'] | ||
param_names = ['freq'] | ||
|
||
def setup(self, freq): | ||
self.freq = freq | ||
self.rng = date_range('1985', periods=1000) | ||
self.rng2 = date_range('1985', periods=1000).to_pydatetime() | ||
|
||
def time_from_date_range(self): | ||
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. you also need to pass the param in the actual 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. Is this in addition to or instead of setting 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. that doesn't matter, it is just needed to let the code actually run. |
||
PeriodIndex(self.rng, freq=self.freq) | ||
|
||
def time_from_pydatetime(self): | ||
PeriodIndex(self.rng2, freq=self.freq) | ||
|
||
|
||
class DataFramePeriodColumn(object): | ||
goal_time = 0.2 | ||
|
||
def setup_cache(self): | ||
rng = pd.period_range(start='1/1/1990', freq='S', periods=20000) | ||
df = pd.DataFrame(index=range(len(rng))) | ||
return rng, df | ||
|
||
def time_setitem_period_column(self, tup): | ||
rng, df = tup | ||
df['col'] = rng | ||
|
||
|
||
class PeriodIndexAlgorithms(object): | ||
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. you could also param this one (I would just call it Algorithms, the 'period' is already in the file name) for ['series', 'index'] 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. I thought about that but decided against it because the two cases treat the data differently, would need a 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. I would rather do a |
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
data = [Period('2011-01', freq='M'), Period('2011-02', freq='M'), | ||
Period('2011-03', freq='M'), Period('2011-04', freq='M')] | ||
self.index = PeriodIndex(data, freq='M') | ||
|
||
def time_drop_duplicates(self): | ||
self.index.drop_duplicates() | ||
|
||
def time_value_counts(self): | ||
self.index.value_counts() | ||
|
||
|
||
class PeriodSeriesAlgorithms(object): | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
data = [Period('2011-01', freq='M'), Period('2011-02', freq='M'), | ||
Period('2011-03', freq='M'), Period('2011-04', freq='M')] | ||
self.series = Series(data * 1000) | ||
|
||
def time_drop_duplicates(self): | ||
self.series.drop_duplicates() | ||
|
||
def time_value_counts(self): | ||
self.series.value_counts() | ||
|
||
|
||
class PeriodStandardIndexing(object): | ||
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. I would just do 'Indexing' ? 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. Name used to be 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. Yes, and the one in your PR is certainly an improvement (since it follows PEP8), but I think the 'period' and 'standard' are just redundant (unless there is another class with non-standard indexing) |
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
|
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.
does this have to be double brackets ?
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.
Not in my admittedly-limited experience. Though the only examples that use both
params
andparam_names
do have 2+ param_names, so do have double double-brackets forparams
.