Skip to content

Convert Sparse ASVs #26704

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 5 commits into from
Jun 16, 2019
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
30 changes: 11 additions & 19 deletions asv_bench/benchmarks/sparse.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import itertools

import numpy as np
import scipy.sparse
from pandas import (SparseSeries, SparseDataFrame, SparseArray, Series,
date_range, MultiIndex)

import pandas as pd
from pandas import MultiIndex, Series, SparseArray, date_range


def make_array(size, dense_proportion, fill_value, dtype):
Expand All @@ -25,10 +24,10 @@ def setup(self):
data = np.random.randn(N)[:-i]
idx = rng[:-i]
data[100:] = np.nan
self.series[i] = SparseSeries(data, index=idx)
self.series[i] = pd.Series(pd.SparseArray(data), index=idx)

def time_series_to_frame(self):
SparseDataFrame(self.series)
pd.DataFrame(self.series)


class SparseArrayConstructor:
Expand All @@ -51,16 +50,9 @@ def setup(self):
N = 1000
self.arr = np.arange(N)
self.sparse = scipy.sparse.rand(N, N, 0.005)
self.dict = dict(zip(range(N), itertools.repeat([0])))

def time_constructor(self):
SparseDataFrame(columns=self.arr, index=self.arr)

def time_from_scipy(self):
SparseDataFrame(self.sparse)

def time_from_dict(self):
SparseDataFrame(self.dict)
pd.DataFrame.sparse.from_spmatrix(self.sparse)


class FromCoo:
Expand All @@ -71,7 +63,7 @@ def setup(self):
shape=(100, 100))

def time_sparse_series_from_coo(self):
SparseSeries.from_coo(self.matrix)
pd.Series.sparse.from_coo(self.matrix)


class ToCoo:
Expand All @@ -82,12 +74,12 @@ def setup(self):
s[100] = -1.0
s[999] = 12.1
s.index = MultiIndex.from_product([range(10)] * 4)
self.ss = s.to_sparse()
self.ss = s.astype("Sparse")

def time_sparse_series_to_coo(self):
self.ss.to_coo(row_levels=[0, 1],
column_levels=[2, 3],
sort_labels=True)
self.ss.sparse.to_coo(row_levels=[0, 1],
column_levels=[2, 3],
sort_labels=True)


class Arithmetic:
Expand Down