Skip to content

WIP/TST: Added test of unstacking two levels with NaN. #9492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

seth-p
Copy link
Contributor

@seth-p seth-p commented Feb 14, 2015

Added a test to test_unstack_nan_index() for unstacking two levels simultaneously when one of them contains a NaN.

Should delete the print() statements before merging...

This is the output I get:

======================================================================
FAIL: test_unstack_nan_index (pandas.tests.test_frame.TestDataFrame)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\seth\github\pandas2\build\lib.win-amd64-3.4\pandas\tests\test_frame.py", line 12439, in test_unstack_nan_index
    assert_series_equal(left, right)
  File "c:\Users\seth\github\pandas2\build\lib.win-amd64-3.4\pandas\util\testing.py", line 674, in assert_series_equal
    assert_almost_equal(left.values, right.values, check_less_precise)
  File "das\src\testing.pyx", line 58, in pandas._testing.assert_almost_equal (pandas\src\testing.c:2745)
  File "das\src\testing.pyx", line 93, in pandas._testing.assert_almost_equal (pandas\src\testing.c:1830)
  File "das\src\testing.pyx", line 135, in pandas._testing.assert_almost_equal (pandas\src\testing.c:2514)
nose.proxy.AssertionError: (very low values) expected 3.00000 but got 0.00000, with decimal 5
-------------------- >> begin captured stdout << ---------------------
dfs=
       C
A B     
a 0    0
  1    1
  2    2
  NaN  3
b 4    4
  5    5
  6    6
  7    7

left=
   A  B
C  a  1    0
      2    1
      4    2
      0    3
   b  6    4
      7    5
   a  0    6
      1    7
dtype: int32

right=
   A  B  
C  a  NaN    3
      0      0
      1      1
      2      2
   b  4      4
      5      5
      6      6
      7      7
dtype: int32

--------------------- >> end captured stdout << ----------------------

@seth-p
Copy link
Contributor Author

seth-p commented Feb 14, 2015

cc: @behzadnouri

@seth-p
Copy link
Contributor Author

seth-p commented Feb 14, 2015

@jreback, @behzadnouri: In view of @behzadnouri's observation #9023 (comment) that implementing DataFrame.unstack() in terms of (my modified) DataFrame.stack() slowed things down tremendously, I tried going the other way and implementing DataFrame.stack() in terms of DataFrame.unstack() (after making a few simple modifications to the latter to support dropna and sequentially). I noticed that then some of my stack() tests were failing, and isolated this case as an example.

@seth-p
Copy link
Contributor Author

seth-p commented Feb 14, 2015

For comparison, this is the result in 0.15.2 in the absence of NaNs.

In [1]: import pandas as pd

In [2]: df = pd.DataFrame({'A': list('aaaabbbb'),'B':range(8), 'C':range(8)})

In [3]: dfs = df.set_index(['A', 'B'])

In [4]: dfs.unstack([0, 1])
Out[4]:
   A  B
C  a  0    0
      1    1
      2    2
      3    3
   b  4    4
      5    5
      6    6
      7    7
dtype: int32

@seth-p seth-p force-pushed the unstack_multi_nan_bug branch from dc68abb to b848ae0 Compare February 14, 2015 20:35
@seth-p seth-p force-pushed the unstack_multi_nan_bug branch from b848ae0 to ba974f1 Compare February 14, 2015 20:39
@seth-p
Copy link
Contributor Author

seth-p commented Feb 14, 2015

[Recommitted code with correct expected right.]

@jreback
Copy link
Contributor

jreback commented Feb 15, 2015

@seth-p pls submit this as a separate issue report

@jreback jreback closed this Feb 15, 2015
@seth-p
Copy link
Contributor Author

seth-p commented Feb 16, 2015

Created #9497.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants