-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: ASV string #19069
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 string #19069
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,119 +1,144 @@ | ||
from .pandas_vb_common import * | ||
import string | ||
import itertools as IT | ||
import pandas.util.testing as testing | ||
import numpy as np | ||
from pandas import Series | ||
import pandas.util.testing as tm | ||
|
||
|
||
class StringMethods(object): | ||
goal_time = 0.2 | ||
class Methods(object): | ||
|
||
def make_series(self, letters, strlen, size): | ||
return Series([str(x) for x in np.fromiter(IT.cycle(letters), count=(size * strlen), dtype='|S1').view('|S{}'.format(strlen))]) | ||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.many = self.make_series(('matchthis' + string.ascii_uppercase), strlen=19, size=10000) | ||
self.few = self.make_series(('matchthis' + (string.ascii_uppercase * 42)), strlen=19, size=10000) | ||
self.s = self.make_series(string.ascii_uppercase, strlen=10, size=10000).str.join('|') | ||
self.s = Series(tm.makeStringIndex(10**5)) | ||
|
||
def time_cat(self): | ||
self.many.str.cat(sep=',') | ||
self.s.str.cat(sep=',') | ||
|
||
def time_center(self): | ||
self.many.str.center(100) | ||
|
||
def time_contains_few(self): | ||
self.few.str.contains('matchthis') | ||
|
||
def time_contains_few_noregex(self): | ||
self.few.str.contains('matchthis', regex=False) | ||
|
||
def time_contains_many(self): | ||
self.many.str.contains('matchthis') | ||
|
||
def time_contains_many_noregex(self): | ||
self.many.str.contains('matchthis', regex=False) | ||
self.s.str.center(100) | ||
|
||
def time_count(self): | ||
self.many.str.count('matchthis') | ||
self.s.str.count('A') | ||
|
||
def time_endswith(self): | ||
self.many.str.endswith('matchthis') | ||
self.s.str.endswith('A') | ||
|
||
def time_extract(self): | ||
self.many.str.extract('(\\w*)matchthis(\\w*)') | ||
self.s.str.extract('(\\w*)A(\\w*)') | ||
|
||
def time_findall(self): | ||
self.many.str.findall('[A-Z]+') | ||
self.s.str.findall('[A-Z]+') | ||
|
||
def time_get(self): | ||
self.many.str.get(0) | ||
|
||
def time_join_split(self): | ||
self.many.str.join('--').str.split('--') | ||
|
||
def time_join_split_expand(self): | ||
self.many.str.join('--').str.split('--', expand=True) | ||
self.s.str.get(0) | ||
|
||
def time_len(self): | ||
self.many.str.len() | ||
self.s.str.len() | ||
|
||
def time_match(self): | ||
self.many.str.match('mat..this') | ||
self.s.str.match('A') | ||
|
||
def time_pad(self): | ||
self.many.str.pad(100, side='both') | ||
|
||
def time_repeat(self): | ||
self.many.str.repeat(list(IT.islice(IT.cycle(range(1, 4)), len(self.many)))) | ||
self.s.str.pad(100, side='both') | ||
|
||
def time_replace(self): | ||
self.many.str.replace('(matchthis)', '\x01\x01') | ||
self.s.str.replace('A', '\x01\x01') | ||
|
||
def time_slice(self): | ||
self.many.str.slice(5, 15, 2) | ||
self.s.str.slice(5, 15, 2) | ||
|
||
def time_startswith(self): | ||
self.many.str.startswith('matchthis') | ||
self.s.str.startswith('A') | ||
|
||
def time_strip(self): | ||
self.many.str.strip('matchthis') | ||
self.s.str.strip('A') | ||
|
||
def time_rstrip(self): | ||
self.many.str.rstrip('matchthis') | ||
self.s.str.rstrip('A') | ||
|
||
def time_lstrip(self): | ||
self.many.str.lstrip('matchthis') | ||
self.s.str.lstrip('A') | ||
|
||
def time_title(self): | ||
self.many.str.title() | ||
self.s.str.title() | ||
|
||
def time_upper(self): | ||
self.many.str.upper() | ||
self.s.str.upper() | ||
|
||
def time_lower(self): | ||
self.many.str.lower() | ||
self.s.str.lower() | ||
|
||
|
||
class Repeat(object): | ||
|
||
goal_time = 0.2 | ||
params = ['int', 'array'] | ||
param_names = ['repeats'] | ||
|
||
def setup(self, repeats): | ||
N = 10**5 | ||
self.s = Series(tm.makeStringIndex(N)) | ||
repeat = {'int': 1, 'array': np.random.randint(1, 3, N)} | ||
self.repeat = repeat[repeats] | ||
|
||
def time_repeat(self, repeats): | ||
self.s.str.repeat(self.repeat) | ||
|
||
|
||
class Contains(object): | ||
|
||
goal_time = 0.2 | ||
params = [True, False] | ||
param_names = ['regex'] | ||
|
||
def setup(self, regex): | ||
self.s = Series(tm.makeStringIndex(10**5)) | ||
|
||
def time_contains(self, regex): | ||
self.s.str.contains('A', regex=regex) | ||
|
||
|
||
class Split(object): | ||
|
||
goal_time = 0.2 | ||
params = [True, False] | ||
param_names = ['expand'] | ||
|
||
def setup(self, expand): | ||
self.s = Series(tm.makeStringIndex(10**5)).str.join('--') | ||
|
||
def time_split(self, expand): | ||
self.s.str.split('--', expand=expand) | ||
|
||
|
||
class Dummies(object): | ||
|
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.s = Series(tm.makeStringIndex(10**5)).str.join('|') | ||
|
||
def time_get_dummies(self): | ||
self.s.str.get_dummies('|') | ||
|
||
|
||
class StringEncode(object): | ||
class Encode(object): | ||
|
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.ser = Series(testing.makeUnicodeIndex()) | ||
self.ser = Series(tm.makeUnicodeIndex()) | ||
|
||
def time_encode_decode(self): | ||
self.ser.str.encode('utf-8').str.decode('utf-8') | ||
|
||
|
||
class StringSlice(object): | ||
class Slice(object): | ||
|
||
goal_time = 0.2 | ||
|
||
def setup(self): | ||
self.s = Series(['abcdefg', np.nan] * 500000) | ||
|
||
def time_series_string_vector_slice(self): | ||
def time_vector_slice(self): | ||
# GH 2602 | ||
self.s.str[:5] |
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
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.
this last is wrong
pandas_tseries
, where did this come from?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 sure;
pandas_tseries
was present here when I started the clean-up. I can remove thisThere 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.
ok let's do, otherwise lgtm.