some new features
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,49 @@
|
||||
"""
|
||||
|
||||
Created on Wed Feb 29 10:34:00 2012
|
||||
|
||||
Author: Josef Perktold
|
||||
"""
|
||||
from statsmodels.compat import lrange
|
||||
|
||||
from itertools import combinations, zip_longest
|
||||
from numpy.testing import assert_
|
||||
|
||||
|
||||
def test_zip_longest():
|
||||
lili = [
|
||||
["a0", "b0", "c0", "d0"],
|
||||
["a1", "b1", "c1"],
|
||||
["a2", "b2", "c2", "d2"],
|
||||
["a3", "b3", "c3", "d3"],
|
||||
["a4", "b4"],
|
||||
]
|
||||
|
||||
transposed = [
|
||||
("a0", "a1", "a2", "a3", "a4"),
|
||||
("b0", "b1", "b2", "b3", "b4"),
|
||||
("c0", "c1", "c2", "c3", None),
|
||||
("d0", None, "d2", "d3", None),
|
||||
]
|
||||
|
||||
assert_(
|
||||
list(zip_longest(*lili)) == transposed,
|
||||
f"{zip_longest(*lili)!r} not equal {transposed!r}",
|
||||
)
|
||||
|
||||
|
||||
def test_combinations():
|
||||
actual = list(combinations("ABCD", 2))
|
||||
desired = [
|
||||
("A", "B"),
|
||||
("A", "C"),
|
||||
("A", "D"),
|
||||
("B", "C"),
|
||||
("B", "D"),
|
||||
("C", "D"),
|
||||
]
|
||||
assert_(actual == desired, f"{actual!r} not equal {desired!r}")
|
||||
|
||||
actual = list(combinations(lrange(4), 3))
|
||||
desired = [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
|
||||
assert_(actual == desired, f"{actual!r} not equal {desired!r}")
|
||||
@ -0,0 +1,42 @@
|
||||
from statsmodels.compat.pandas import PD_LT_1_4, is_float_index, is_int_index
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("int_type", ["u", "i"])
|
||||
@pytest.mark.parametrize("int_size", [1, 2, 4, 8])
|
||||
def test_is_int_index(int_type, int_size):
|
||||
index = pd.Index(np.arange(100), dtype=f"{int_type}{int_size}")
|
||||
assert is_int_index(index)
|
||||
assert not is_float_index(index)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("float_size", [4, 8])
|
||||
def test_is_float_index(float_size):
|
||||
index = pd.Index(np.arange(100.0), dtype=f"f{float_size}")
|
||||
assert is_float_index(index)
|
||||
assert not is_int_index(index)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not PD_LT_1_4, reason="Requires U/Int64Index")
|
||||
def test_legacy_int_index():
|
||||
from pandas import Int64Index, UInt64Index
|
||||
|
||||
index = Int64Index(np.arange(100))
|
||||
assert is_int_index(index)
|
||||
assert not is_float_index(index)
|
||||
|
||||
index = UInt64Index(np.arange(100))
|
||||
assert is_int_index(index)
|
||||
assert not is_float_index(index)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not PD_LT_1_4, reason="Requires Float64Index")
|
||||
def test_legacy_float_index():
|
||||
from pandas import Float64Index
|
||||
|
||||
index = Float64Index(np.arange(100))
|
||||
assert not is_int_index(index)
|
||||
assert is_float_index(index)
|
||||
@ -0,0 +1,79 @@
|
||||
from numpy.testing import assert_equal
|
||||
from statsmodels.compat.scipy import _next_regular
|
||||
|
||||
|
||||
def test_next_regular():
|
||||
hams = {
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 3,
|
||||
4: 4,
|
||||
5: 5,
|
||||
6: 6,
|
||||
7: 8,
|
||||
8: 8,
|
||||
14: 15,
|
||||
15: 15,
|
||||
16: 16,
|
||||
17: 18,
|
||||
1021: 1024,
|
||||
1536: 1536,
|
||||
51200000: 51200000,
|
||||
510183360: 510183360,
|
||||
510183360 + 1: 512000000,
|
||||
511000000: 512000000,
|
||||
854296875: 854296875,
|
||||
854296875 + 1: 859963392,
|
||||
196608000000: 196608000000,
|
||||
196608000000 + 1: 196830000000,
|
||||
8789062500000: 8789062500000,
|
||||
8789062500000 + 1: 8796093022208,
|
||||
206391214080000: 206391214080000,
|
||||
206391214080000 + 1: 206624260800000,
|
||||
470184984576000: 470184984576000,
|
||||
470184984576000 + 1: 470715894135000,
|
||||
7222041363087360: 7222041363087360,
|
||||
7222041363087360 + 1: 7230196133913600,
|
||||
# power of 5 5**23
|
||||
11920928955078125: 11920928955078125,
|
||||
11920928955078125 - 1: 11920928955078125,
|
||||
# power of 3 3**34
|
||||
16677181699666569: 16677181699666569,
|
||||
16677181699666569 - 1: 16677181699666569,
|
||||
# power of 2 2**54
|
||||
18014398509481984: 18014398509481984,
|
||||
18014398509481984 - 1: 18014398509481984,
|
||||
# above this, int(ceil(n)) == int(ceil(n+1))
|
||||
19200000000000000: 19200000000000000,
|
||||
19200000000000000 + 1: 19221679687500000,
|
||||
288230376151711744: 288230376151711744,
|
||||
288230376151711744 + 1: 288325195312500000,
|
||||
288325195312500000 - 1: 288325195312500000,
|
||||
288325195312500000: 288325195312500000,
|
||||
288325195312500000 + 1: 288555831593533440,
|
||||
# power of 3 3**83
|
||||
3 ** 83 - 1: 3 ** 83,
|
||||
3 ** 83: 3 ** 83,
|
||||
# power of 2 2**135
|
||||
2 ** 135 - 1: 2 ** 135,
|
||||
2 ** 135: 2 ** 135,
|
||||
# power of 5 5**57
|
||||
5 ** 57 - 1: 5 ** 57,
|
||||
5 ** 57: 5 ** 57,
|
||||
# http://www.drdobbs.com/228700538
|
||||
# 2**96 * 3**1 * 5**13
|
||||
2 ** 96 * 3 ** 1 * 5 ** 13 - 1: 2 ** 96 * 3 ** 1 * 5 ** 13,
|
||||
2 ** 96 * 3 ** 1 * 5 ** 13: 2 ** 96 * 3 ** 1 * 5 ** 13,
|
||||
2 ** 96 * 3 ** 1 * 5 ** 13 + 1: 2 ** 43 * 3 ** 11 * 5 ** 29,
|
||||
# 2**36 * 3**69 * 5**7
|
||||
2 ** 36 * 3 ** 69 * 5 ** 7 - 1: 2 ** 36 * 3 ** 69 * 5 ** 7,
|
||||
2 ** 36 * 3 ** 69 * 5 ** 7: 2 ** 36 * 3 ** 69 * 5 ** 7,
|
||||
2 ** 36 * 3 ** 69 * 5 ** 7 + 1: 2 ** 90 * 3 ** 32 * 5 ** 9,
|
||||
# 2**37 * 3**44 * 5**42
|
||||
2 ** 37 * 3 ** 44 * 5 ** 42 - 1: 2 ** 37 * 3 ** 44 * 5 ** 42,
|
||||
2 ** 37 * 3 ** 44 * 5 ** 42: 2 ** 37 * 3 ** 44 * 5 ** 42,
|
||||
2 ** 37 * 3 ** 44 * 5 ** 42 + 1: 2 ** 20 * 3 ** 106 * 5 ** 7,
|
||||
}
|
||||
|
||||
for x, y in hams.items():
|
||||
assert_equal(_next_regular(x), y)
|
||||
Reference in New Issue
Block a user