Skip to content

Commit

Permalink
cache and remove boxing
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Dec 20, 2016
1 parent 02906ce commit 7d27d8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
25 changes: 25 additions & 0 deletions asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ def time_value_counts_pindex(self):
self.i.value_counts()


class period_standard_indexing(object):
goal_time = 0.2

def setup(self):
self.index = PeriodIndex(start='1985', periods=1000, freq='D')
self.series = Series(range(1000), index=self.index)
self.period = self.index[500]

def time_get_loc(self):
self.index.get_loc(self.period)

def time_shape(self):
self.index.shape

def time_shallow_copy(self):
self.index._shallow_copy()

def time_series_loc(self):
self.series.loc[self.period]

def time_align(self):
DataFrame({'a': self.series, 'b': self.series[:500]})

def time_intersection(self):
self.index[:750].intersection(self.index[250:])
8 changes: 4 additions & 4 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,22 +842,22 @@ def data(self):
@property
def itemsize(self):
""" return the size of the dtype of the item of the underlying data """
return self.values.itemsize
return self._values.itemsize

@property
def nbytes(self):
""" return the number of bytes in the underlying data """
return self.values.nbytes
return self._values.nbytes

@property
def strides(self):
""" return the strides of the underlying data """
return self.values.strides
return self._values.strides

@property
def size(self):
""" return the number of elements in the underlying data """
return self.values.size
return self._values.size

@property
def flags(self):
Expand Down
7 changes: 4 additions & 3 deletions pandas/tseries/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
if (len(values) > 0 and is_float_dtype(values)):
raise TypeError("PeriodIndex can't take floats")
else:
return PeriodIndex(values, name=name, freq=freq, **kwargs)
return cls(values, name=name, freq=freq, **kwargs)

values = np.array(values, dtype='int64', copy=False)

Expand All @@ -326,6 +326,8 @@ def _shallow_copy(self, values=None, **kwargs):
if kwargs.get('freq') is None:
# freq must be provided
kwargs['freq'] = self.freq
if values is None:
values = self._values
return super(PeriodIndex, self)._shallow_copy(values=values, **kwargs)

def _coerce_scalar_to_index(self, item):
Expand Down Expand Up @@ -356,9 +358,8 @@ def __contains__(self, key):
def asi8(self):
return self._values.view('i8')

@property
@cache_readonly
def _int64index(self):
# do not cache, same as .asi8
return Int64Index(self.asi8, name=self.name, fastpath=True)

@property
Expand Down

0 comments on commit 7d27d8b

Please sign in to comment.