Skip to content

ASV: add benchmarks for Series.array and extract_array #31277

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 1 commit into from
Jan 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions asv_bench/benchmarks/attrs_caching.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import numpy as np

import pandas as pd
from pandas import DataFrame

try:
from pandas.util import cache_readonly
except ImportError:
from pandas.util.decorators import cache_readonly

try:
from pandas.core.construction import extract_array
except ImportError:
extract_array = None


class DataFrameAttributes:
def setup(self):
Expand All @@ -20,6 +26,33 @@ def time_set_index(self):
self.df.index = self.cur_index


class SeriesArrayAttribute:

params = [["numeric", "object", "category", "datetime64", "datetime64tz"]]
param_names = ["dtype"]

def setup(self, dtype):
if dtype == "numeric":
self.series = pd.Series([1, 2, 3])
elif dtype == "object":
self.series = pd.Series(["a", "b", "c"], dtype=object)
elif dtype == "category":
self.series = pd.Series(["a", "b", "c"], dtype="category")
elif dtype == "datetime64":
self.series = pd.Series(pd.date_range("2013", periods=3))
elif dtype == "datetime64tz":
self.series = pd.Series(pd.date_range("2013", periods=3, tz="UTC"))

def time_array(self, dtype):
self.series.array

def time_extract_array(self, dtype):
extract_array(self.series)

def time_extract_array_numpy(self, dtype):
extract_array(self.series, extract_numpy=True)


class CacheReadonly:
def setup(self):
class Foo:
Expand Down