当前位置: 首页>>代码示例>>Python>>正文


Python FrozenNDArray.copy方法代码示例

本文整理汇总了Python中pandas.core.base.FrozenNDArray.copy方法的典型用法代码示例。如果您正苦于以下问题:Python FrozenNDArray.copy方法的具体用法?Python FrozenNDArray.copy怎么用?Python FrozenNDArray.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.core.base.FrozenNDArray的用法示例。


在下文中一共展示了FrozenNDArray.copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestFrozenNDArray

# 需要导入模块: from pandas.core.base import FrozenNDArray [as 别名]
# 或者: from pandas.core.base.FrozenNDArray import copy [as 别名]
class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase):
    mutable_methods = ('put', 'itemset', 'fill')
    unicode_container = FrozenNDArray([u("\u05d0"), u("\u05d1"), "c"])

    def setUp(self):
        self.lst = [3, 5, 7, -2]
        self.container = FrozenNDArray(self.lst)
        self.klass = FrozenNDArray

    def test_shallow_copying(self):
        original = self.container.copy()
        self.assertIsInstance(self.container.view(), FrozenNDArray)
        self.assertFalse(isinstance(
            self.container.view(np.ndarray), FrozenNDArray))
        self.assertIsNot(self.container.view(), self.container)
        self.assert_numpy_array_equal(self.container, original)
        # shallow copy should be the same too
        self.assertIsInstance(self.container._shallow_copy(), FrozenNDArray)

        # setting should not be allowed
        def testit(container):
            container[0] = 16

        self.check_mutable_error(testit, self.container)

    def test_values(self):
        original = self.container.view(np.ndarray).copy()
        n = original[0] + 15
        vals = self.container.values()
        self.assert_numpy_array_equal(original, vals)
        self.assertIsNot(original, vals)
        vals[0] = n
        self.assertIsInstance(self.container, pd.core.base.FrozenNDArray)
        self.assert_numpy_array_equal(self.container.values(), original)
        self.assertEqual(vals[0], n)
开发者ID:nateGeorge,项目名称:pandas,代码行数:37,代码来源:test_base.py

示例2: TestFrozenNDArray

# 需要导入模块: from pandas.core.base import FrozenNDArray [as 别名]
# 或者: from pandas.core.base.FrozenNDArray import copy [as 别名]
class TestFrozenNDArray(CheckImmutable, unittest.TestCase):
    mutable_methods = ('put', 'itemset', 'fill')

    def setUp(self):
        self.lst = [3, 5, 7, -2]
        self.container = FrozenNDArray(self.lst)
        self.klass = FrozenNDArray

    def test_shallow_copying(self):
        original = self.container.copy()
        assert_isinstance(self.container.view(), FrozenNDArray)
        self.assert_(not isinstance(self.container.view(np.ndarray), FrozenNDArray))
        self.assert_(self.container.view() is not self.container)
        self.assert_(np.array_equal(self.container, original))
        # shallow copy should be the same too
        assert_isinstance(self.container._shallow_copy(), FrozenNDArray)
        # setting should not be allowed
        def testit(container): container[0] = 16

        self.check_mutable_error(testit, self.container)

    def test_values(self):
        original = self.container.view(np.ndarray).copy()
        n = original[0] + 15
        vals = self.container.values()
        self.assert_(np.array_equal(original, vals))
        self.assert_(original is not vals)
        vals[0] = n
        self.assert_(np.array_equal(self.container, original))
        self.assertEqual(vals[0], n)
开发者ID:X1mengYu,项目名称:pandas,代码行数:32,代码来源:test_base.py


注:本文中的pandas.core.base.FrozenNDArray.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。