clean up PeriodIndex constructor by max-sixty · Pull Request #13277 · pandas-dev/pandas (original) (raw)
actually why don't you make this change (as I have a couple of more comments).
diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py
index 903b4e3..cefe1cf 100644
--- a/pandas/tseries/period.py
+++ b/pandas/tseries/period.py
@@ -239,9 +239,7 @@ class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin, Int64Index):
if not isinstance(data, (np.ndarray, PeriodIndex,
DatetimeIndex, Int64Index)):
if is_scalar(data) or isinstance(data, Period):
- raise ValueError('PeriodIndex() must be called with a '
- 'collection of some kind, %s was passed'
- % repr(data))
+ cls._scalar_data_error(data)
# other iterable of some kind
if not isinstance(data, (list, tuple)):
diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py
index c7fd4ae..8ec2fae 100644
--- a/pandas/tseries/tests/test_period.py
+++ b/pandas/tseries/tests/test_period.py
@@ -1753,7 +1753,7 @@ class TestPeriodIndex(tm.TestCase):
self.assertRaises(ValueError, PeriodIndex, idx._values)
self.assertRaises(ValueError, PeriodIndex, list(idx._values))
- self.assertRaises(ValueError, PeriodIndex,
+ self.assertRaises(TypeError, PeriodIndex,
data=Period('2007', freq='A'))
result = PeriodIndex(iter(idx))