@@ -2660,11 +2660,13 @@ def test_rolling_functions_window_non_shrinkage(self):
2660
2660
def test_rolling_functions_window_non_shrinkage_binary(self):
2661
2661
2662
2662
# corr/cov return a MI DataFrame
2663
- df = DataFrame([[1, 5], [3, 2], [3, 9], [-1, 0]], columns=['A', 'B'])
2663
+ df = DataFrame([[1, 5], [3, 2], [3, 9], [-1, 0]],
2664
+ columns=Index(['A', 'B'], name='foo'),
2665
+ index=Index(range(4), name='bar'))
2664
2666
df_expected = DataFrame(
2665
- columns=df.columns ,
2667
+ columns=Index(['A', 'B']) ,
2666
2668
index=pd.MultiIndex.from_product([df.index, df.columns],
2667
- names=['major ', 'minor ']),
2669
+ names=['bar ', 'foo ']),
2668
2670
dtype='float64')
2669
2671
functions = [lambda x: (x.rolling(window=10, min_periods=5)
2670
2672
.cov(x, pairwise=True)),
@@ -2739,17 +2741,17 @@ def test_moment_functions_zero_length_pairwise(self):
2739
2741
2740
2742
df1 = DataFrame()
2741
2743
df1_expected = df1
2742
- df2 = DataFrame(columns=['a'])
2744
+ df2 = DataFrame(columns=Index(['a'], name='foo'),
2745
+ index=Index([], name='bar'))
2743
2746
df2['a'] = df2['a'].astype('float64')
2744
2747
2745
2748
df1_expected = DataFrame(
2746
- index=pd.MultiIndex.from_product([df1.columns, df1.index],
2747
- names=['major', 'minor']),
2748
- columns=df1.columns)
2749
+ index=pd.MultiIndex.from_product([df1.index, df1.columns]),
2750
+ columns=Index([]))
2749
2751
df2_expected = DataFrame(
2750
- index=pd.MultiIndex.from_product([df2.columns , df2.index ],
2751
- names=['major ', 'minor ']),
2752
- columns=df2.columns ,
2752
+ index=pd.MultiIndex.from_product([df2.index , df2.columns ],
2753
+ names=['bar ', 'foo ']),
2754
+ columns=Index(['a']) ,
2753
2755
dtype='float64')
2754
2756
2755
2757
functions = [lambda x: (x.expanding(min_periods=5)
@@ -2770,35 +2772,51 @@ def test_moment_functions_zero_length_pairwise(self):
2770
2772
2771
2773
def test_expanding_cov_pairwise_diff_length(self):
2772
2774
# GH 7512
2773
- df1 = DataFrame([[1, 5], [3, 2], [3, 9]], columns=['A', 'B'])
2774
- df1a = DataFrame([[1, 5], [3, 9]], index=[0, 2], columns=['A', 'B'])
2775
- df2 = DataFrame([[5, 6], [None, None], [2, 1]], columns=['X', 'Y'])
2776
- df2a = DataFrame([[5, 6], [2, 1]], index=[0, 2], columns=['X', 'Y'])
2775
+ df1 = DataFrame([[1, 5], [3, 2], [3, 9]],
2776
+ columns=Index(['A', 'B'], name='foo'))
2777
+ df1a = DataFrame([[1, 5], [3, 9]],
2778
+ index=[0, 2],
2779
+ columns=Index(['A', 'B'], name='foo'))
2780
+ df2 = DataFrame([[5, 6], [None, None], [2, 1]],
2781
+ columns=Index(['X', 'Y'], name='foo'))
2782
+ df2a = DataFrame([[5, 6], [2, 1]],
2783
+ index=[0, 2],
2784
+ columns=Index(['X', 'Y'], name='foo'))
2785
+ # TODO: xref gh-15826
2786
+ # .loc is not preserving the names
2777
2787
result1 = df1.expanding().cov(df2a, pairwise=True).loc[2]
2778
2788
result2 = df1.expanding().cov(df2a, pairwise=True).loc[2]
2779
2789
result3 = df1a.expanding().cov(df2, pairwise=True).loc[2]
2780
2790
result4 = df1a.expanding().cov(df2a, pairwise=True).loc[2]
2781
2791
expected = DataFrame([[-3.0, -6.0], [-5.0, -10.0]],
2782
2792
columns=['A', 'B'],
2783
- index=Index(['X', 'Y'], name='minor '))
2793
+ index=Index(['X', 'Y'], name='foo '))
2784
2794
tm.assert_frame_equal(result1, expected)
2785
2795
tm.assert_frame_equal(result2, expected)
2786
2796
tm.assert_frame_equal(result3, expected)
2787
2797
tm.assert_frame_equal(result4, expected)
2788
2798
2789
2799
def test_expanding_corr_pairwise_diff_length(self):
2790
2800
# GH 7512
2791
- df1 = DataFrame([[1, 2], [3, 2], [3, 4]], columns=['A', 'B'])
2792
- df1a = DataFrame([[1, 2], [3, 4]], index=[0, 2], columns=['A', 'B'])
2793
- df2 = DataFrame([[5, 6], [None, None], [2, 1]], columns=['X', 'Y'])
2794
- df2a = DataFrame([[5, 6], [2, 1]], index=[0, 2], columns=['X', 'Y'])
2801
+ df1 = DataFrame([[1, 2], [3, 2], [3, 4]],
2802
+ columns=['A', 'B'],
2803
+ index=Index(range(3), name='bar'))
2804
+ df1a = DataFrame([[1, 2], [3, 4]],
2805
+ index=Index([0, 2], name='bar'),
2806
+ columns=['A', 'B'])
2807
+ df2 = DataFrame([[5, 6], [None, None], [2, 1]],
2808
+ columns=['X', 'Y'],
2809
+ index=Index(range(3), name='bar'))
2810
+ df2a = DataFrame([[5, 6], [2, 1]],
2811
+ index=Index([0, 2], name='bar'),
2812
+ columns=['X', 'Y'])
2795
2813
result1 = df1.expanding().corr(df2, pairwise=True).loc[2]
2796
2814
result2 = df1.expanding().corr(df2a, pairwise=True).loc[2]
2797
2815
result3 = df1a.expanding().corr(df2, pairwise=True).loc[2]
2798
2816
result4 = df1a.expanding().corr(df2a, pairwise=True).loc[2]
2799
2817
expected = DataFrame([[-1.0, -1.0], [-1.0, -1.0]],
2800
2818
columns=['A', 'B'],
2801
- index=Index(['X', 'Y'], name='minor' ))
2819
+ index=Index(['X', 'Y']))
2802
2820
tm.assert_frame_equal(result1, expected)
2803
2821
tm.assert_frame_equal(result2, expected)
2804
2822
tm.assert_frame_equal(result3, expected)
0 commit comments