def test_constructor_dtypes(self):
for idx in [Index(np.array([1, 2, 3], dtype=int)),
Index(np.array([1, 2, 3], dtype=int), dtype=int),
Index([1, 2, 3], dtype=int)]:
self.assertIsInstance(idx, Int64Index)
# these should coerce
for idx in [Index(np.array([1., 2., 3.], dtype=float), dtype=int),
Index([1., 2., 3.], dtype=int)]:
self.assertIsInstance(idx, Int64Index)
for idx in [Index(np.array([1., 2., 3.], dtype=float)),
Index(np.array([1, 2, 3], dtype=int), dtype=float),
Index(np.array([1., 2., 3.], dtype=float), dtype=float),
Index([1, 2, 3], dtype=float),
Index([1., 2., 3.], dtype=float)]:
self.assertIsInstance(idx, Float64Index)
for idx in [Index(np.array([True, False, True], dtype=bool)),
Index([True, False, True]),
Index(np.array([True, False, True], dtype=bool), dtype=bool),
Index([True, False, True], dtype=bool)]:
self.assertIsInstance(idx, Index)
self.assertEqual(idx.dtype, object)
for idx in [Index(np.array([1, 2, 3], dtype=int), dtype='category'),
Index([1, 2, 3], dtype='category'),
Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')]), dtype='category'),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)], dtype='category')]:
self.assertIsInstance(idx, CategoricalIndex)
for idx in [Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')])),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)])]:
self.assertIsInstance(idx, DatetimeIndex)
for idx in [Index(np.array([np.datetime64('2011-01-01'),
np.datetime64('2011-01-02')]), dtype=object),
Index([datetime(2011, 1, 1),
datetime(2011, 1, 2)], dtype=object)]:
self.assertNotIsInstance(idx, DatetimeIndex)
self.assertIsInstance(idx, Index)
self.assertEqual(idx.dtype, object)
for idx in [Index(np.array([np.timedelta64(1, 'D'), np.timedelta64(
1, 'D')])), Index([timedelta(1), timedelta(1)])]:
self.assertIsInstance(idx, TimedeltaIndex)
for idx in [Index(np.array([np.timedelta64(1, 'D'),
np.timedelta64(1, 'D')]), dtype=object),
Index([timedelta(1), timedelta(1)], dtype=object)]:
self.assertNotIsInstance(idx, TimedeltaIndex)
self.assertIsInstance(idx, Index)
self.assertEqual(idx.dtype, object)
test_base.py 文件源码
python
阅读 30
收藏 0
点赞 0
评论 0
评论列表
文章目录