MCPcopy
hub / github.com/pandas-dev/pandas / test_int64_overflow

Method test_int64_overflow

pandas/tests/test_sorting.py:46–83  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

44class TestSorting:
45 @pytest.mark.slow
46 def test_int64_overflow(self):
47 B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
48 A = np.arange(2500)
49 df = DataFrame(
50 {
51 "A": A,
52 "B": B,
53 "C": A,
54 "D": B,
55 "E": A,
56 "F": B,
57 "G": A,
58 "H": B,
59 "values": np.random.default_rng(2).standard_normal(2500),
60 }
61 )
62
63 lg = df.groupby(["A", "B", "C", "D", "E", "F", "G", "H"])
64 rg = df.groupby(["H", "G", "F", "E", "D", "C", "B", "A"])
65
66 left = lg.sum()["values"]
67 right = rg.sum()["values"]
68
69 exp_index, _ = left.index.sortlevel()
70 tm.assert_index_equal(left.index, exp_index)
71
72 exp_index, _ = right.index.sortlevel(0)
73 tm.assert_index_equal(right.index, exp_index)
74
75 tups = list(map(tuple, df[["A", "B", "C", "D", "E", "F", "G", "H"]].values))
76 tups = com.asarray_tuplesafe(tups)
77
78 expected = df.groupby(tups).sum()["values"]
79
80 for k, v in expected.items():
81 assert left[k] == right[k[::-1]]
82 assert left[k] == v
83 assert len(left) == len(right)
84
85 def test_int64_overflow_groupby_large_range(self):
86 # GH9096

Callers

nothing calls this directly

Calls 5

groupbyMethod · 0.95
DataFrameClass · 0.90
sumMethod · 0.45
sortlevelMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected