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


Python sparse.shift方法代码示例

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


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

示例1: test_shift

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift(self):
        series = SparseSeries([nan, 1., 2., 3., nan, nan], index=np.arange(6))

        shifted = series.shift(0)
        # assert shifted is not series
        tm.assert_sp_series_equal(shifted, series)

        f = lambda s: s.shift(1)
        _dense_series_compare(series, f)

        f = lambda s: s.shift(-2)
        _dense_series_compare(series, f)

        series = SparseSeries([nan, 1., 2., 3., nan, nan],
                              index=bdate_range('1/1/2000', periods=6))
        f = lambda s: s.shift(2, freq='B')
        _dense_series_compare(series, f)

        f = lambda s: s.shift(2, freq=BDay())
        _dense_series_compare(series, f) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_series.py

示例2: test_shift

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift(self):
        series = SparseSeries([nan, 1., 2., 3., nan, nan], index=np.arange(6))

        shifted = series.shift(0)
        assert shifted is not series
        tm.assert_sp_series_equal(shifted, series)

        f = lambda s: s.shift(1)
        _dense_series_compare(series, f)

        f = lambda s: s.shift(-2)
        _dense_series_compare(series, f)

        series = SparseSeries([nan, 1., 2., 3., nan, nan],
                              index=bdate_range('1/1/2000', periods=6))
        f = lambda s: s.shift(2, freq='B')
        _dense_series_compare(series, f)

        f = lambda s: s.shift(2, freq=BDay())
        _dense_series_compare(series, f) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_series.py

示例3: test_shift_dtype

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_dtype(self):
        # GH 12908
        orig = pd.Series([1, 2, 3, 4], dtype=np.int64)

        sparse = orig.to_sparse()
        tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse())

        sparse = orig.to_sparse(fill_value=np.nan)
        tm.assert_sp_series_equal(sparse.shift(0),
                                  orig.shift(0).to_sparse(fill_value=np.nan))
        # shift(1) or more span changes dtype to float64
        tm.assert_sp_series_equal(sparse.shift(1), orig.shift(1).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(2), orig.shift(2).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(3), orig.shift(3).to_sparse())

        tm.assert_sp_series_equal(sparse.shift(-1), orig.shift(-1).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-2), orig.shift(-2).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-3), orig.shift(-3).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-4), orig.shift(-4).to_sparse()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_series.py

示例4: test_shift_dtype_fill_value

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_dtype_fill_value(self):
        # GH 12908
        orig = pd.Series([1, 0, 0, 4], dtype=np.int64)

        for v in [0, 1, np.nan]:
            sparse = orig.to_sparse(fill_value=v)

            tm.assert_sp_series_equal(sparse.shift(0),
                                      orig.shift(0).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(1),
                                      orig.shift(1).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(2),
                                      orig.shift(2).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(3),
                                      orig.shift(3).to_sparse(fill_value=v))

            tm.assert_sp_series_equal(sparse.shift(-1),
                                      orig.shift(-1).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(-2),
                                      orig.shift(-2).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(-3),
                                      orig.shift(-3).to_sparse(fill_value=v))
            tm.assert_sp_series_equal(sparse.shift(-4),
                                      orig.shift(-4).to_sparse(fill_value=v)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:test_series.py

示例5: test_shift_dtype

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_dtype(self):
        # GH 12908
        orig = pd.Series([1, 2, 3, 4], dtype=np.int64)

        sparse = orig.to_sparse()
        tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse())

        sparse = orig.to_sparse(fill_value=np.nan)
        tm.assert_sp_series_equal(sparse.shift(0),
                                  orig.shift(0).to_sparse(fill_value=np.nan))
        # shift(1) or more span changes dtype to float64
        # XXX: SparseSeries doesn't need to shift dtype here.
        # Do we want to astype in shift, for backwards compat?
        # If not, document it.
        tm.assert_sp_series_equal(sparse.shift(1).astype('f8'),
                                  orig.shift(1).to_sparse(kind='integer'))
        tm.assert_sp_series_equal(sparse.shift(2).astype('f8'),
                                  orig.shift(2).to_sparse(kind='integer'))
        tm.assert_sp_series_equal(sparse.shift(3).astype('f8'),
                                  orig.shift(3).to_sparse(kind='integer'))

        tm.assert_sp_series_equal(sparse.shift(-1).astype('f8'),
                                  orig.shift(-1).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-2).astype('f8'),
                                  orig.shift(-2).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-3).astype('f8'),
                                  orig.shift(-3).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-4).astype('f8'),
                                  orig.shift(-4).to_sparse(),
                                  check_kind=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:test_series.py

示例6: test_shift_dtype_fill_value

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_dtype_fill_value(self, fill_value, periods):
        # GH 12908
        orig = pd.Series([1, 0, 0, 4], dtype=np.dtype('int64'))

        sparse = orig.to_sparse(fill_value=fill_value)

        result = sparse.shift(periods)
        expected = orig.shift(periods).to_sparse(fill_value=fill_value)

        tm.assert_sp_series_equal(result, expected,
                                  check_kind=False,
                                  consolidate_block_indices=True) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_series.py

示例7: test_shift_nan

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_nan(self):
        # GH 12908
        orig = pd.Series([np.nan, 2, np.nan, 4, 0, np.nan, 0])
        sparse = orig.to_sparse()

        tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(1), orig.shift(1).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(2), orig.shift(2).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(3), orig.shift(3).to_sparse())

        tm.assert_sp_series_equal(sparse.shift(-1), orig.shift(-1).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-2), orig.shift(-2).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-3), orig.shift(-3).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-4), orig.shift(-4).to_sparse())

        sparse = orig.to_sparse(fill_value=0)
        tm.assert_sp_series_equal(sparse.shift(0),
                                  orig.shift(0).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(1),
                                  orig.shift(1).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(2),
                                  orig.shift(2).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(3),
                                  orig.shift(3).to_sparse(fill_value=0))

        tm.assert_sp_series_equal(sparse.shift(-1),
                                  orig.shift(-1).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(-2),
                                  orig.shift(-2).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(-3),
                                  orig.shift(-3).to_sparse(fill_value=0))
        tm.assert_sp_series_equal(sparse.shift(-4),
                                  orig.shift(-4).to_sparse(fill_value=0)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:35,代码来源:test_series.py

示例8: test_shift_nan

# 需要导入模块: from scipy import sparse [as 别名]
# 或者: from scipy.sparse import shift [as 别名]
def test_shift_nan(self):
        # GH 12908
        orig = pd.Series([np.nan, 2, np.nan, 4, 0, np.nan, 0])
        sparse = orig.to_sparse()

        tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(1), orig.shift(1).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(2), orig.shift(2).to_sparse(),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(3), orig.shift(3).to_sparse(),
                                  check_kind=False)

        tm.assert_sp_series_equal(sparse.shift(-1), orig.shift(-1).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-2), orig.shift(-2).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-3), orig.shift(-3).to_sparse())
        tm.assert_sp_series_equal(sparse.shift(-4), orig.shift(-4).to_sparse())

        sparse = orig.to_sparse(fill_value=0)
        tm.assert_sp_series_equal(
            sparse.shift(0),
            orig.shift(0).to_sparse(fill_value=sparse.fill_value)
        )
        tm.assert_sp_series_equal(sparse.shift(1),
                                  orig.shift(1).to_sparse(fill_value=0),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(2),
                                  orig.shift(2).to_sparse(fill_value=0),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(3),
                                  orig.shift(3).to_sparse(fill_value=0),
                                  check_kind=False)

        tm.assert_sp_series_equal(sparse.shift(-1),
                                  orig.shift(-1).to_sparse(fill_value=0),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-2),
                                  orig.shift(-2).to_sparse(fill_value=0),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-3),
                                  orig.shift(-3).to_sparse(fill_value=0),
                                  check_kind=False)
        tm.assert_sp_series_equal(sparse.shift(-4),
                                  orig.shift(-4).to_sparse(fill_value=0),
                                  check_kind=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:48,代码来源:test_series.py


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