Skip to content

Commit 72356c7

Browse files
committed
Add in missing whitespace
1 parent d75bf39 commit 72356c7

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

hack.py

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import pandas as pd
2+
import pdb
3+
4+
a = pd.RangeIndex(0, 99, step=5)
5+
b = pd.RangeIndex(200, 100, step=-5)
6+
7+
print(a)
8+
print(b)
9+
print(a.union(b, sort=None))
10+
#pdb.set_trace()
11+
print(a.union(b, sort=False))
12+
print(b.union(a, sort=None))
13+
print(b.union(a, sort=False))
14+
15+
RI = pd.RangeIndex
16+
a = RI(0, -10, -1)
17+
b = RI(-10, -20, -1)
18+
print()
19+
print(a)
20+
print(b)
21+
print(a.union(b, sort=None))
22+
print(a.union(b, sort=False))
23+
24+
a = RI(0, -10, -1)
25+
b = RI(-10, -20, -1)
26+
print()
27+
print(a)
28+
print(b)
29+
print(a.union(b, sort=None))
30+
print(a.union(b, sort=False))
31+
32+
print()
33+
print("Same step and end=start")
34+
a = RI(0, 10, 2)
35+
b = RI(10, 12, 2)
36+
print(a._int64index)
37+
print(b._int64index)
38+
print(a.union(b, sort=None))
39+
print(a.union(b, sort=False))
40+
41+
print()
42+
print("Overlap and same step")
43+
a = RI(0, 10, 2)
44+
b = RI(8, 20, 2)
45+
print(a._int64index)
46+
print(b._int64index)
47+
print(a.union(b, sort=None))
48+
print(a.union(b, sort=False))
49+
50+
print()
51+
print("Same step but no overlap")
52+
a = RI(0, 10, 2)
53+
b = RI(12, 20, 2)
54+
print(a._int64index)
55+
print(b._int64index)
56+
print(a.union(b, sort=None))
57+
print(a.union(b, sort=False))
58+
59+
# How to not sort this while also return RI?
60+
a = RI(0, 10, 2)
61+
b = RI(1, 10, 2)
62+
print()
63+
print(a._int64index)
64+
print(b._int64index)
65+
print(a.union(b, sort=None))
66+
print(a.union(b, sort=False))
67+
68+
# How to not sort this while also return RI?
69+
a = RI(0, 11, 2)
70+
b = RI(1, 12, 2)
71+
print()
72+
print(a._int64index)
73+
print(b._int64index)
74+
print(a.union(b, sort=None))
75+
# pdb.set_trace()
76+
print(a.union(b, sort=False))
77+
78+
# (RI(0, -10, -1), RI(0, -10, -1), RI(0, -10, -1)),
79+
# sorts the result by default. Do we want to try to not sort
80+
# for sort=False? Could easily be done if we accept Int64Index
81+
# as a result. But then we will have I64 even in cases when
82+
# it might be relatively easy to have not sorted. Much harder if
83+
# we want RI in all cases
84+
# We can not sort here while also return a RI?
85+
# (RI(0, -10, -1), RI(-10, -20, -1), RI(-19, 1, 1))]
86+
87+
# When could we actually return a RI?
88+
# * The steps are equal
89+
# * The second range starts right after the first range or the second range is within the first range
90+
91+
"""
92+
expected_notsorted = [RI(0, 10, 1),
93+
I64(list(range(5, 20, 1)) + list(range(5))),
94+
I64(list(range(10, 20, 1)) + list(range(10))),
95+
RI(0, -10, -1),
96+
I64(list(range(-10, -20, -1)) + list(range(0, -10, -1))),
97+
I64(list(range(1, 10, 2)) + list(range(0, 10, 2))),
98+
I64(list(range(1, 12, 2)) + list(range(0, 11, 2))),
99+
I64(list(range(-2, 24, 4)) + list(range(0, 21, 4))),
100+
I64(list(range(-1, -21, -2)) + list(range(0, -20, -2))),
101+
I64(list(range(0, 100, 20)) + [5, 10, 15, 25, 30, 35, 45, 50, 55, 65, 70, 75, 85, 90, 95]),
102+
I64(list(range(5, -100, -20)) + [0, -5, -10, -20, -25, -30, -40, -45, -50, -60, -65, -70, -80, -85, -90]),
103+
I64(list(range(1, -12, -4)) + [0, -1, -2, -4, -5, -6, -8, -9, -10]),
104+
RI(0),
105+
RI(0, -10, -2),
106+
I64([100] + list(range(0, 100, 2))),
107+
I64([-100, 2] + list(range(0, -100, -2))),
108+
I64(list(range(0, -50, -3)) + [-1, -2, -4, -5, -7, -8, -10, -11, -13, -14, -16, -17, -19, -20, -22, -23, -25, -26, -28, -29, -31, -32, -34, -35, -37, -38, -40, -41, -43, -44, -46, -47] + list(range(-49, -100, -1))),
109+
I64([5, 0]),
110+
I64([-5, 0, 5]),
111+
I64([4, 0, 1, 2]),
112+
RI(0, 10, 1),
113+
I64([1, 5, 6])]
114+
115+
for ((idx1, idx2), expected) in zip(inputs, expected_notsorted):
116+
res1 = idx2.union(idx1, sort=False)
117+
tm.assert_index_equal(res1, expected, exact=True)
118+
"""
119+
120+
rng_a = pd.date_range('1/1/2012', periods=4, freq='3H')
121+
rng_b = pd.date_range('1/1/2012', periods=4, freq='4H')
122+
print(rng_a.union(rng_b, sort=None))
123+
print(rng_a.union(rng_b, sort=False))

pandas/tests/indexes/test_range.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
F64 = Float64Index
1818
OI = Index
1919

20+
2021
class TestRangeIndex(Numeric):
2122
_holder = RangeIndex
2223
_compat_props = ['shape', 'ndim', 'size']

0 commit comments

Comments
 (0)