@@ -243,9 +243,7 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None,
243
243
if not isinstance (data , (np .ndarray , PeriodIndex ,
244
244
DatetimeIndex , Int64Index )):
245
245
if is_scalar (data ) or isinstance (data , Period ):
246
- raise ValueError ('PeriodIndex() must be called with a '
247
- 'collection of some kind, %s was passed'
248
- % repr (data ))
246
+ cls ._scalar_data_error (data )
249
247
250
248
# other iterable of some kind
251
249
if not isinstance (data , (list , tuple )):
@@ -254,7 +252,7 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None,
254
252
data = np .asarray (data )
255
253
256
254
# datetime other than period
257
- if np . issubdtype (data .dtype , np . datetime64 ):
255
+ if is_datetime64_dtype (data .dtype ):
258
256
data = dt64arr_to_periodarr (data , freq , tz )
259
257
return cls ._from_ordinals (data , name = name , freq = freq )
260
258
@@ -297,8 +295,7 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
297
295
values = np .array (values , copy = False )
298
296
if len (values ) > 0 and is_float_dtype (values ):
299
297
raise TypeError ("PeriodIndex can't take floats" )
300
- else :
301
- return cls (values , name = name , freq = freq , ** kwargs )
298
+ return cls (values , name = name , freq = freq , ** kwargs )
302
299
303
300
return cls ._from_ordinals (values , name , freq , ** kwargs )
304
301
@@ -324,12 +321,13 @@ def _shallow_copy_with_infer(self, values=None, **kwargs):
324
321
""" we always want to return a PeriodIndex """
325
322
return self ._shallow_copy (values = values , ** kwargs )
326
323
327
- def _shallow_copy (self , values = None , ** kwargs ):
328
- if kwargs . get ( ' freq' ) is None :
329
- kwargs [ ' freq' ] = self .freq
324
+ def _shallow_copy (self , values = None , freq = None , ** kwargs ):
325
+ if freq is None :
326
+ freq = self .freq
330
327
if values is None :
331
328
values = self ._values
332
- return super (PeriodIndex , self )._shallow_copy (values = values , ** kwargs )
329
+ return super (PeriodIndex , self )._shallow_copy (values = values ,
330
+ freq = freq , ** kwargs )
333
331
334
332
def _coerce_scalar_to_index (self , item ):
335
333
"""
0 commit comments