Skip to content

TST: Clean test_format.py #9227

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

Merged
merged 1 commit into from
Mar 5, 2015
Merged

TST: Clean test_format.py #9227

merged 1 commit into from
Mar 5, 2015

Conversation

alanhdu
Copy link
Contributor

@alanhdu alanhdu commented Jan 12, 2015

Mostly just stylistic changes. The only substantive one is the test now on line 56 (has_horizontally_truncated_repr). I can't figure what the test was supposed to be doing. Suggestions?

Original Test:

def has_horizontally_truncated_repr(df):
    try: # Check header row
        fst_line = np.array(repr(df).splitlines()[0].split())
        cand_col = np.where(fst_line=='...')[0][0]
    except:
        return False
    # Make sure each row has this ... in the same place
    r = repr(df)
    for ix,l in enumerate(r.splitlines()):
         if not r.split()[cand_col] == '...':
             return False
    return True

New Test:

def has_horizontally_truncated_repr(df):
    try: # Check header row
        fst_line = np.array(repr(df).splitlines()[0].split())
        cand_col = np.where(fst_line=='...')[0][0]
    except:
        return False
    # Make sure each row has this ... in the same place
    return repr(df).split()[cand_col] == "..."

@jorisvandenbossche
Copy link
Member

@alanhdu I am not very familiar with these tests, but doesn't it just do what the comment says? "Make sure each row has this ... in the same place" So it iterates over the rows of the dataframe (for ix,l in enumerate(r.splitlines()):), and then it checks that each line has these ... truncuation marks.

But, I see now, probably there was just a mistake in the loop that r should be l ?

@alanhdu
Copy link
Contributor Author

alanhdu commented Jan 12, 2015

Replacing the r.split()[cand_col] with l.split()[cand_col] makes the test fail.

@jorisvandenbossche
Copy link
Member

yes, because the ... in the first line and the subsequent lines is not located in the same place if there is no df.columns.name, and the last lines do not contain ...

As in:

In [54]: df = pd.DataFrame([[1,2,3], [4,5,6]], columns=['A', 'B', 'C'])

In [55]: pd.options.display.max_columns = 2

In [56]: df
Out[56]: 
   A ...  C
0  1 ...  3
1  4 ...  6

[2 rows x 3 columns]

So the test was indeed somewhat to simple. The question is if this should be tested (... on all lines), or if it is good to use your simplified version only testing the first line.

cc @bjonen ?

@jreback jreback added the Testing pandas testing functions or related to the test suite label Jan 13, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 13, 2015
@bjonen
Copy link
Contributor

bjonen commented Jan 13, 2015

Perhaps a compromise is to test if there is at least one '...' in each line.

@@ -55,11 +53,7 @@ def has_horizontally_truncated_repr(df):
except:
return False
# Make sure each row has this ... in the same place
r = repr(df)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would restore this section. You are testing something slightly different here.

@jreback
Copy link
Contributor

jreback commented Jan 18, 2015

@alanhdu minor restoration. pls squash and get this in.

@alanhdu
Copy link
Contributor Author

alanhdu commented Jan 19, 2015

@bjonen ... doesn't always appear on each line.

In [21]: w = pd.get_option("display.max_rows") + 1

In [22]: pd.DataFrame({k: np.arange(5) for k in np.arange(w)})
Out[22]: 
   0   1   2   3   4   5   6   7   8   9  ...  51  52  53  54  55  56  57  58  \
0   0   0   0   0   0   0   0   0   0   0 ...   0   0   0   0   0   0   0   0   
1   1   1   1   1   1   1   1   1   1   1 ...   1   1   1   1   1   1   1   1   
2   2   2   2   2   2   2   2   2   2   2 ...   2   2   2   2   2   2   2   2   
3   3   3   3   3   3   3   3   3   3   3 ...   3   3   3   3   3   3   3   3   
4   4   4   4   4   4   4   4   4   4   4 ...   4   4   4   4   4   4   4   4   

   59  60  
0   0   0  
1   1   1  
2   2   2  
3   3   3  
4   4   4  

[5 rows x 61 columns]

@alanhdu
Copy link
Contributor Author

alanhdu commented Jan 19, 2015

@jreback Reverted and squashed.

@jorisvandenbossche
Copy link
Member

Can you rebase? Currently it cannot be merged as is. Normally:

git fetch upstream
git rebase upstream/master

and then push force should suffice.

* pd -> pandas
* assert statement -> nosetest assert
@alanhdu
Copy link
Contributor Author

alanhdu commented Jan 20, 2015

Rebased.

jreback added a commit that referenced this pull request Mar 5, 2015
TST: Clean test_format.py
@jreback jreback merged commit ec96aab into pandas-dev:master Mar 5, 2015
@jreback
Copy link
Contributor

jreback commented Mar 5, 2015

@alanhdu thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants