Skip to content

Commit 9995694

Browse files
committed
ENH: add is_full method to PeriodIndex close #1114
1 parent b3a6107 commit 9995694

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pandas/tseries/period.py

+13
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,19 @@ def __iter__(self):
656656
def is_all_dates(self):
657657
return True
658658

659+
@property
660+
def is_full(self):
661+
"""
662+
Returns True if there are any missing periods from start to end
663+
"""
664+
if len(self) == 0:
665+
return True
666+
if not self.is_monotonic:
667+
raise ValueError('Index is not monotonic')
668+
values = self.values
669+
return ((values[1:] - values[:-1]) < 2).all()
670+
671+
659672
@property
660673
def freqstr(self):
661674
return self.freq

pandas/tseries/tests/test_period.py

+17
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,23 @@ def _check_field(self, periodindex, fieldname):
14641464
for x, val in zip(periodindex, field_idx):
14651465
assert_equal(getattr(x, fieldname), val)
14661466

1467+
def test_is_full(self):
1468+
index = PeriodIndex([2005, 2007, 2009], freq='A')
1469+
self.assert_(not index.is_full)
1470+
1471+
index = PeriodIndex([2005, 2006, 2007], freq='A')
1472+
self.assert_(index.is_full)
1473+
1474+
index = PeriodIndex([2005, 2005, 2007], freq='A')
1475+
self.assert_(not index.is_full)
1476+
1477+
index = PeriodIndex([2005, 2005, 2006], freq='A')
1478+
self.assert_(index.is_full)
1479+
1480+
index = PeriodIndex([2006, 2005, 2005], freq='A')
1481+
self.assertRaises(ValueError, getattr, index, 'is_full')
1482+
1483+
self.assert_(index[:0].is_full)
14671484

14681485
def _permute(obj):
14691486
return obj.take(np.random.permutation(len(obj)))

0 commit comments

Comments
 (0)