本文整理汇总了Python中pandas.UInt64Index方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.UInt64Index方法的具体用法?Python pandas.UInt64Index怎么用?Python pandas.UInt64Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.UInt64Index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constructor
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_constructor(self):
idx = UInt64Index([1, 2, 3])
res = Index([1, 2, 3], dtype=np.uint64)
tm.assert_index_equal(res, idx)
idx = UInt64Index([1, 2**63])
res = Index([1, 2**63], dtype=np.uint64)
tm.assert_index_equal(res, idx)
idx = UInt64Index([1, 2**63])
res = Index([1, 2**63])
tm.assert_index_equal(res, idx)
idx = Index([-1, 2**63], dtype=object)
res = Index(np.array([-1, 2**63], dtype=object))
tm.assert_index_equal(res, idx)
示例2: test_get_indexer
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_get_indexer(self):
target = UInt64Index(np.arange(10).astype('uint64') * 5 + 2**63)
indexer = self.index.get_indexer(target)
expected = np.array([0, -1, 1, 2, 3, 4,
-1, -1, -1, -1], dtype=np.intp)
tm.assert_numpy_array_equal(indexer, expected)
target = UInt64Index(np.arange(10).astype('uint64') * 5 + 2**63)
indexer = self.index.get_indexer(target, method='pad')
expected = np.array([0, 0, 1, 2, 3, 4,
4, 4, 4, 4], dtype=np.intp)
tm.assert_numpy_array_equal(indexer, expected)
target = UInt64Index(np.arange(10).astype('uint64') * 5 + 2**63)
indexer = self.index.get_indexer(target, method='backfill')
expected = np.array([0, 1, 1, 2, 3, 4,
-1, -1, -1, -1], dtype=np.intp)
tm.assert_numpy_array_equal(indexer, expected)
示例3: test_map_dictlike
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_map_dictlike(idx, mapper):
if isinstance(idx, (pd.CategoricalIndex, pd.IntervalIndex)):
pytest.skip("skipping tests for {}".format(type(idx)))
identity = mapper(idx.values, idx)
# we don't infer to UInt64 for a dict
if isinstance(idx, pd.UInt64Index) and isinstance(identity, dict):
expected = idx.astype('int64')
else:
expected = idx
result = idx.map(identity)
tm.assert_index_equal(result, expected)
# empty mappable
expected = pd.Index([np.nan] * len(idx))
result = idx.map(mapper(expected, idx))
tm.assert_index_equal(result, expected)
示例4: test_map_dictlike
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_map_dictlike(self, mapper):
index = self.create_index()
if isinstance(index, (pd.CategoricalIndex, pd.IntervalIndex)):
pytest.skip("skipping tests for {}".format(type(index)))
identity = mapper(index.values, index)
# we don't infer to UInt64 for a dict
if isinstance(index, pd.UInt64Index) and isinstance(identity, dict):
expected = index.astype('int64')
else:
expected = index
result = index.map(identity)
tm.assert_index_equal(result, expected)
# empty mappable
expected = pd.Index([np.nan] * len(index))
result = index.map(mapper(expected, index))
tm.assert_index_equal(result, expected)
示例5: test_astype_uint
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_astype_uint(self):
arr = timedelta_range('1H', periods=2)
expected = pd.UInt64Index(
np.array([3600000000000, 90000000000000], dtype="uint64")
)
tm.assert_index_equal(arr.astype("uint64"), expected)
tm.assert_index_equal(arr.astype("uint32"), expected)
示例6: test_hasnans_isnans
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_hasnans_isnans(self):
# GH 11343, added tests for hasnans / isnans
for name, index in self.indices.items():
if isinstance(index, MultiIndex):
pass
else:
idx = index.copy()
# cases in indices doesn't include NaN
expected = np.array([False] * len(idx), dtype=bool)
tm.assert_numpy_array_equal(idx._isnan, expected)
assert idx.hasnans is False
idx = index.copy()
values = np.asarray(idx.values)
if len(index) == 0:
continue
elif isinstance(index, DatetimeIndexOpsMixin):
values[1] = iNaT
elif isinstance(index, (Int64Index, UInt64Index)):
continue
else:
values[1] = np.nan
if isinstance(index, PeriodIndex):
idx = index.__class__(values, freq=index.freq)
else:
idx = index.__class__(values)
expected = np.array([False] * len(idx), dtype=bool)
expected[1] = True
tm.assert_numpy_array_equal(idx._isnan, expected)
assert idx.hasnans is True
示例7: test_fillna
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_fillna(self):
# GH 11343
for name, index in self.indices.items():
if len(index) == 0:
pass
elif isinstance(index, MultiIndex):
idx = index.copy()
msg = "isna is not defined for MultiIndex"
with pytest.raises(NotImplementedError, match=msg):
idx.fillna(idx[0])
else:
idx = index.copy()
result = idx.fillna(idx[0])
tm.assert_index_equal(result, idx)
assert result is not idx
msg = "'value' must be a scalar, passed: "
with pytest.raises(TypeError, match=msg):
idx.fillna([idx[0]])
idx = index.copy()
values = np.asarray(idx.values)
if isinstance(index, DatetimeIndexOpsMixin):
values[1] = iNaT
elif isinstance(index, (Int64Index, UInt64Index)):
continue
else:
values[1] = np.nan
if isinstance(index, PeriodIndex):
idx = index.__class__(values, freq=index.freq)
else:
idx = index.__class__(values)
expected = np.array([False] * len(idx), dtype=bool)
expected[1] = True
tm.assert_numpy_array_equal(idx._isnan, expected)
assert idx.hasnans is True
示例8: test_map
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_map(self):
# callable
index = self.create_index()
# we don't infer UInt64
if isinstance(index, pd.UInt64Index):
expected = index.astype('int64')
else:
expected = index
result = index.map(lambda x: x)
tm.assert_index_equal(result, expected)
示例9: setup_method
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def setup_method(self, method):
vals = [2**63, 2**63 + 10, 2**63 + 15, 2**63 + 20, 2**63 + 25]
self.indices = dict(index=UInt64Index(vals),
index_dec=UInt64Index(reversed(vals)))
self.setup_indices()
示例10: create_index
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def create_index(self):
return UInt64Index(np.arange(5, dtype='uint64'))
示例11: test_join_inner
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_join_inner(self):
other = UInt64Index(2**63 + np.array(
[7, 12, 25, 1, 2, 10], dtype='uint64'))
other_mono = UInt64Index(2**63 + np.array(
[1, 2, 7, 10, 12, 25], dtype='uint64'))
# not monotonic
res, lidx, ridx = self.index.join(other, how='inner',
return_indexers=True)
# no guarantee of sortedness, so sort for comparison purposes
ind = res.argsort()
res = res.take(ind)
lidx = lidx.take(ind)
ridx = ridx.take(ind)
eres = UInt64Index(2**63 + np.array([10, 25], dtype='uint64'))
elidx = np.array([1, 4], dtype=np.intp)
eridx = np.array([5, 2], dtype=np.intp)
assert isinstance(res, UInt64Index)
tm.assert_index_equal(res, eres)
tm.assert_numpy_array_equal(lidx, elidx)
tm.assert_numpy_array_equal(ridx, eridx)
# monotonic
res, lidx, ridx = self.index.join(other_mono, how='inner',
return_indexers=True)
res2 = self.index.intersection(other_mono)
tm.assert_index_equal(res, res2)
elidx = np.array([1, 4], dtype=np.intp)
eridx = np.array([3, 5], dtype=np.intp)
assert isinstance(res, UInt64Index)
tm.assert_index_equal(res, eres)
tm.assert_numpy_array_equal(lidx, elidx)
tm.assert_numpy_array_equal(ridx, eridx)
示例12: test_join_outer
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_join_outer(self):
other = UInt64Index(2**63 + np.array(
[7, 12, 25, 1, 2, 10], dtype='uint64'))
other_mono = UInt64Index(2**63 + np.array(
[1, 2, 7, 10, 12, 25], dtype='uint64'))
# not monotonic
# guarantee of sortedness
res, lidx, ridx = self.index.join(other, how='outer',
return_indexers=True)
noidx_res = self.index.join(other, how='outer')
tm.assert_index_equal(res, noidx_res)
eres = UInt64Index(2**63 + np.array(
[0, 1, 2, 7, 10, 12, 15, 20, 25], dtype='uint64'))
elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp)
eridx = np.array([-1, 3, 4, 0, 5, 1, -1, -1, 2], dtype=np.intp)
assert isinstance(res, UInt64Index)
tm.assert_index_equal(res, eres)
tm.assert_numpy_array_equal(lidx, elidx)
tm.assert_numpy_array_equal(ridx, eridx)
# monotonic
res, lidx, ridx = self.index.join(other_mono, how='outer',
return_indexers=True)
noidx_res = self.index.join(other_mono, how='outer')
tm.assert_index_equal(res, noidx_res)
elidx = np.array([0, -1, -1, -1, 1, -1, 2, 3, 4], dtype=np.intp)
eridx = np.array([-1, 0, 1, 2, 3, 4, -1, -1, 5], dtype=np.intp)
assert isinstance(res, UInt64Index)
tm.assert_index_equal(res, eres)
tm.assert_numpy_array_equal(lidx, elidx)
tm.assert_numpy_array_equal(ridx, eridx)
示例13: test_astype_uint
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_astype_uint(self):
arr = date_range('2000', periods=2)
expected = pd.UInt64Index(
np.array([946684800000000000, 946771200000000000], dtype="uint64")
)
tm.assert_index_equal(arr.astype("uint64"), expected)
tm.assert_index_equal(arr.astype("uint32"), expected)
示例14: test_astype_uint
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_astype_uint(self):
arr = period_range('2000', periods=2)
expected = pd.UInt64Index(np.array([10957, 10958], dtype='uint64'))
tm.assert_index_equal(arr.astype("uint64"), expected)
tm.assert_index_equal(arr.astype("uint32"), expected)
示例15: test_fillna
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import UInt64Index [as 别名]
def test_fillna(idx):
# GH 11343
# TODO: Remove or Refactor. Not Implemented for MultiIndex
for name, index in [('idx', idx), ]:
if len(index) == 0:
pass
elif isinstance(index, MultiIndex):
idx = index.copy()
msg = "isna is not defined for MultiIndex"
with pytest.raises(NotImplementedError, match=msg):
idx.fillna(idx[0])
else:
idx = index.copy()
result = idx.fillna(idx[0])
tm.assert_index_equal(result, idx)
assert result is not idx
msg = "'value' must be a scalar, passed: "
with pytest.raises(TypeError, match=msg):
idx.fillna([idx[0]])
idx = index.copy()
values = idx.values
if isinstance(index, DatetimeIndexOpsMixin):
values[1] = iNaT
elif isinstance(index, (Int64Index, UInt64Index)):
continue
else:
values[1] = np.nan
if isinstance(index, PeriodIndex):
idx = index.__class__(values, freq=index.freq)
else:
idx = index.__class__(values)
expected = np.array([False] * len(idx), dtype=bool)
expected[1] = True
tm.assert_numpy_array_equal(idx._isnan, expected)
assert idx.hasnans is True