Skip to content

Commit 7d27d8b

Browse files
committed
cache and remove boxing
1 parent 02906ce commit 7d27d8b

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

asv_bench/benchmarks/period.py

+25
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,28 @@ def time_value_counts_pindex(self):
4949
self.i.value_counts()
5050

5151

52+
class period_standard_indexing(object):
53+
goal_time = 0.2
54+
55+
def setup(self):
56+
self.index = PeriodIndex(start='1985', periods=1000, freq='D')
57+
self.series = Series(range(1000), index=self.index)
58+
self.period = self.index[500]
59+
60+
def time_get_loc(self):
61+
self.index.get_loc(self.period)
62+
63+
def time_shape(self):
64+
self.index.shape
65+
66+
def time_shallow_copy(self):
67+
self.index._shallow_copy()
68+
69+
def time_series_loc(self):
70+
self.series.loc[self.period]
71+
72+
def time_align(self):
73+
DataFrame({'a': self.series, 'b': self.series[:500]})
74+
75+
def time_intersection(self):
76+
self.index[:750].intersection(self.index[250:])

pandas/core/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -842,22 +842,22 @@ def data(self):
842842
@property
843843
def itemsize(self):
844844
""" return the size of the dtype of the item of the underlying data """
845-
return self.values.itemsize
845+
return self._values.itemsize
846846

847847
@property
848848
def nbytes(self):
849849
""" return the number of bytes in the underlying data """
850-
return self.values.nbytes
850+
return self._values.nbytes
851851

852852
@property
853853
def strides(self):
854854
""" return the strides of the underlying data """
855-
return self.values.strides
855+
return self._values.strides
856856

857857
@property
858858
def size(self):
859859
""" return the number of elements in the underlying data """
860-
return self.values.size
860+
return self._values.size
861861

862862
@property
863863
def flags(self):

pandas/tseries/period.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
305305
if (len(values) > 0 and is_float_dtype(values)):
306306
raise TypeError("PeriodIndex can't take floats")
307307
else:
308-
return PeriodIndex(values, name=name, freq=freq, **kwargs)
308+
return cls(values, name=name, freq=freq, **kwargs)
309309

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

@@ -326,6 +326,8 @@ def _shallow_copy(self, values=None, **kwargs):
326326
if kwargs.get('freq') is None:
327327
# freq must be provided
328328
kwargs['freq'] = self.freq
329+
if values is None:
330+
values = self._values
329331
return super(PeriodIndex, self)._shallow_copy(values=values, **kwargs)
330332

331333
def _coerce_scalar_to_index(self, item):
@@ -356,9 +358,8 @@ def __contains__(self, key):
356358
def asi8(self):
357359
return self._values.view('i8')
358360

359-
@property
361+
@cache_readonly
360362
def _int64index(self):
361-
# do not cache, same as .asi8
362363
return Int64Index(self.asi8, name=self.name, fastpath=True)
363364

364365
@property

0 commit comments

Comments
 (0)