Skip to content
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

DOC: Use a standard header for all rst files #24086

Merged
merged 3 commits into from
Dec 9, 2018

Conversation

saurav2608
Copy link

@pep8speaks
Copy link

Hello @saurav2608! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Dec 4, 2018

Codecov Report

Merging #24086 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24086   +/-   ##
=======================================
  Coverage   42.51%   42.51%           
=======================================
  Files         161      161           
  Lines       51691    51691           
=======================================
  Hits        21975    21975           
  Misses      29716    29716
Flag Coverage Δ
#single 42.51% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 940104e...ecba524. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 4, 2018

Codecov Report

Merging #24086 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24086   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files         162      162           
  Lines       51723    51723           
=======================================
  Hits        47694    47694           
  Misses       4029     4029
Flag Coverage Δ
#multiple 90.61% <ø> (ø) ⬆️
#single 43.03% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 949b148...1704878. Read the comment docs.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Looks quite good, if you can just revert the removal of datetime., and check the failures.

@FHaase do you want to take a look here?

@@ -1333,20 +1314,20 @@ The :ref:`Timedeltas <timedeltas.timedeltas>` docs.

s.max() - s

s - datetime.datetime(2011, 1, 1, 3, 5)
Copy link
Member

Choose a reason for hiding this comment

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

can you revert those, the import should be import datetime

Copy link
Author

Choose a reason for hiding this comment

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

Done

import functools
import glob
import itertools
import os
Copy link
Member

Choose a reason for hiding this comment

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

All those shouldn't be here, should be visibly imported in the places where they are used.

Can you check if we the currently validated flake8-rst files (the ones not ignored in setup.cfg), removing them raises an error?

That would apply to all the imports except import pandas as pd and import numpy as np.

Don't fix the errors in this PR if there are more than couple, but if you can show how many failures are without the imports, that would be great.

Copy link
Author

Choose a reason for hiding this comment

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

these are also done.

@jreback jreback added the Docs label Dec 4, 2018
@datapythonista
Copy link
Member

@saurav2608 will you have time to add the numpy and pandas imports to setup.cfg, remove the others from the header, and add the needed ones to where they are used?

@FHaase
Copy link
Contributor

FHaase commented Dec 5, 2018

@FHaase do you want to take a look here?

Once your suggestions are implemented I'm fine with that.

@saurav2608 adding this to setup.cfg in the [flake8-rst] section should fix most of the F821 issues.

[flake8-rst]
bootstrap = 
    import numpy as np
    import pandas as pd
...

@saurav2608
Copy link
Author

@saurav2608 will you have time to add the numpy and pandas imports to setup.cfg, remove the others from the header, and add the needed ones to where they are used?

I will definitely complete this. I am traveling for work, but will get this done by tomorrow.

@jreback
Copy link
Contributor

jreback commented Dec 5, 2018

@datapythonista I assume you want to merge this before anything else touches the .rst's themselves?

@datapythonista
Copy link
Member

I don't think we have anything else modifying the .rst headers, but if we do would be nice to wait a bit and avoid conflicts in this PR, yes.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

@saurav2608 Thanks for working on this!

import glob
import itertools
import os

import numpy as np
from pandas import *
Copy link
Member

Choose a reason for hiding this comment

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

This from pandas import * should also not be here. If it was needed for the whatsnew files (where the common imports were used now?), I would still keep that separate until we fix the examples in the whatsnew files to not need this.

Copy link
Author

Choose a reason for hiding this comment

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

This from pandas import * should also not be here. If it was needed for the whatsnew files (where the common imports were used now?), I would still keep that separate until we fix the examples in the whatsnew files to not need this.

Okay - I have added from pandas import * to all whatsnew files. We have to revisit all the whatnew files.

Copy link
Author

Choose a reason for hiding this comment

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

I have added from pandas import * to all the whatsnew file. We have to review all of them later to see where files actually need the import (my guess is all of them).

@datapythonista
Copy link
Member

@saurav2608 did you push your changes? I still can see all the imports in header. The only imports in header should be import numpy as np and import pandas as pd. Thanks!

@saurav2608
Copy link
Author

@saurav2608 did you push your changes? I still can see all the imports in header. The only imports in header should be import numpy as np and import pandas as pd. Thanks!

No I have not pushed it yes. I am making the changes now.

@datapythonista datapythonista self-assigned this Dec 7, 2018
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

looks great, just couple of questions, not sure if I'm missing something

import pandas as pd
import numpy as np
import pandas as pd # noqa: F811
import numpy as np # noqa: F811
Copy link
Member

Choose a reason for hiding this comment

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

why don't we use the header here? you can add the F811 to the --bootstrap parameter value if needed

Copy link
Author

Choose a reason for hiding this comment

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

This is a tutorial of sorts and the tutorial walks thru the process of importing pandas and numpy visibly (not with a :supress: ). I think without the visible import of pandas the tutorial will not make sense.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. But can you still include the header in those files? Besides the imports, there is other stuff. And we will potentially add more, and expect to be applied to 100% of rst files. Thanks!

import pandas as pd
from pandas.util import testing as tm
import numpy as np # noqa: F811
import pandas as pd # noqa: F811
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Author

Choose a reason for hiding this comment

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

This similar to the issue above. The tutorial presents a complete block of code to be copied and saved as a .py file. Without the explicit import, anyone following the tutorial will not be able to replicate the results. It might make sense to include this block as a non executable block.

@@ -207,7 +207,7 @@ installed), make sure you have `pytest

::

>>> import pandas as pd
>>> import pandas as pd # noqa: F811
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Author

Choose a reason for hiding this comment

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

On this I agree with you. I can remove the explicit import.

@datapythonista
Copy link
Member

what I don't understand is why the noqa F811 is needed. In header, after the import pandas as pd, we use pd to set options, don't we? And I think for numpy we set the seed. So, F811 shouldn't be raised if the module is being used after the import and before the repeated one, or should it?

CC: @FHaase

@saurav2608
Copy link
Author

There is another behavior I am unable to understand. This build fails on linting error on the file comparison_with_sql.rst. comparison_with_sql.rst:17:5: F811 redefinition of unused 'pd' from line 2. This file does not have the header block (I have not touched this file in this commit). Thus pd is defined for the first time at line 17. Is the bootstrap parameter causing F811?

@jorisvandenbossche
Copy link
Member

@saurav2608 general note: when updating the PR, can you add new commits instead of amending or squashing with the previous one? That makes it easier to review only the new changes.
(When the PR is merged, it will be squashed anyway, so it is no problem to have "fixup" commits).

@datapythonista
Copy link
Member

datapythonista commented Dec 7, 2018

@saurav2608, if you want you can remove the noqa, and if the files are being checked for flake8-rst and ci/code_checks.py reports errors, you can add the files to the ignore list for flake8-rst in setup.cfg.

This way we can merge this, avoid conflicts, and we can fix the flake8-rst errors in a new PR

@saurav2608
Copy link
Author

@datapythonista, I have removed the #noqa and added the files to the ignore list. I have also added header to all the rst file.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

looks great, thanks a lot for working on this

do you mind creating yourself the follow up issues for:

  • Removing the from pandas import * in the whatsnew files
  • Fix the errors with flake8-rst that report errors in the import pandas as pd...
  • Remove the randn = numpy.random.randn and replace the randn by np.random.randn

Thanks!

@saurav2608
Copy link
Author

Sure, will open the issues.

@jreback jreback added this to the 0.24.0 milestone Dec 7, 2018
@jreback
Copy link
Contributor

jreback commented Dec 7, 2018

@datapythonista looks ok. are you sure you wan tthe from pandas import * in the older release notes? or just not worth it to fix

@datapythonista
Copy link
Member

I think for now makes sense to have the from pandas import *, so we can validate the rest of the files for errors (and avoid ignoring them and not validate any error). I guess there won't be many errors, and if that's the case it's probably worth to leave them clean at some point (surely not a priority).

@saurav2608
Copy link
Author

@datapythonista , @jreback : Can you please merge this? I will create follow-up issues for the revised code.

@jreback
Copy link
Contributor

jreback commented Dec 9, 2018

@saurav2608 pls merge master. @datapythonista ok by me.

@datapythonista
Copy link
Member

@saurav2608 merged the conflict myself, merging on green

@datapythonista datapythonista merged commit 3bc2831 into pandas-dev:master Dec 9, 2018
@datapythonista
Copy link
Member

Thanks @saurav2608 for taking care of this, good improvement

@saurav2608 saurav2608 deleted the rst-header branch December 9, 2018 18:00
@datapythonista
Copy link
Member

@saurav2608 I already fixed the errors when importing import pandas as pd (and numpy) in the files in #24182, no need to open an issue for those

@@ -1081,6 +1069,8 @@ Option 1: pass rows explicitly to skip rows

.. ipython:: python

from pandas.compat import StringIO
Copy link
Member

Choose a reason for hiding this comment

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

Side note: in the public docs I think we should use the standard python from io import StringIO (as I don't think we should recommend people normal users to use pandas.compat)

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Use a standard header for all rst files
7 participants