@@ -201,6 +201,8 @@ def _string_data_error(cls, data):
201
201
202
202
@classmethod
203
203
def _coerce_to_ndarray (cls , data ):
204
+ """coerces data to ndarray, raises on scalar data. Converts other
205
+ iterables to list first and then to array. Does not touch ndarrays."""
204
206
205
207
if not isinstance (data , np .ndarray ):
206
208
if np .isscalar (data ):
@@ -1624,7 +1626,7 @@ class Int64Index(Index):
1624
1626
Parameters
1625
1627
----------
1626
1628
data : array-like (1-dimensional)
1627
- dtype : NumPy dtype (default: object )
1629
+ dtype : NumPy dtype (default: int64 )
1628
1630
copy : bool
1629
1631
Make a copy of input ndarray
1630
1632
name : object
@@ -1651,33 +1653,8 @@ def __new__(cls, data, dtype=None, copy=False, name=None, fastpath=False):
1651
1653
subarr .name = name
1652
1654
return subarr
1653
1655
1654
- if not isinstance (data , np .ndarray ):
1655
- if np .isscalar (data ):
1656
- cls ._scalar_data_error (data )
1657
-
1658
- data = cls ._coerce_to_ndarray (data )
1659
-
1660
- if issubclass (data .dtype .type , compat .string_types ):
1661
- cls ._string_data_error (data )
1662
-
1663
- elif issubclass (data .dtype .type , np .integer ):
1664
- # don't force the upcast as we may be dealing
1665
- # with a platform int
1666
- if dtype is None or not issubclass (np .dtype (dtype ).type , np .integer ):
1667
- dtype = np .int64
1668
-
1669
- subarr = np .array (data , dtype = dtype , copy = copy )
1670
- else :
1671
- subarr = np .array (data , dtype = np .int64 , copy = copy )
1672
- if len (data ) > 0 :
1673
- if (subarr != data ).any ():
1674
- raise TypeError ('Unsafe NumPy casting, you must '
1675
- 'explicitly cast' )
1676
-
1677
- # other iterable of some kind
1678
- if not isinstance (data , (list , tuple )):
1679
- data = list (data )
1680
- data = np .asarray (data )
1656
+ # isscalar, generators handled in coerce_to_ndarray
1657
+ data = cls ._coerce_to_ndarray (data )
1681
1658
1682
1659
if issubclass (data .dtype .type , compat .string_types ):
1683
1660
cls ._string_data_error (data )
@@ -1767,11 +1744,7 @@ def __new__(cls, data, dtype=None, copy=False, name=None, fastpath=False):
1767
1744
subarr .name = name
1768
1745
return subarr
1769
1746
1770
- if not isinstance (data , np .ndarray ):
1771
- if np .isscalar (data ):
1772
- cls ._scalar_data_error (data )
1773
-
1774
- data = cls ._coerce_to_ndarray (data )
1747
+ data = cls ._coerce_to_ndarray (data )
1775
1748
1776
1749
if issubclass (data .dtype .type , compat .string_types ):
1777
1750
cls ._string_data_error (data )
0 commit comments