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: Fixing flake8 errors in cookbook.rst #23837

Merged
merged 12 commits into from
Nov 24, 2018

Conversation

saurav2608
Copy link

@datapythonista datapythonista changed the title Cookbook doc DOC: Fixing flake8 errors in cookbook.rst Nov 21, 2018
@datapythonista datapythonista added Docs Code Style Code style, linting, code_checks Clean labels Nov 21, 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.

Great changes, thanks @saurav2608.

I added some comments on things that IMO would make the formatting more consistent and clearer. If you don't mind fixing those.

doc/source/cookbook.rst Show resolved Hide resolved
doc/source/cookbook.rst Show resolved Hide resolved
doc/source/cookbook.rst Show resolved Hide resolved
@@ -105,11 +108,14 @@ Splitting

.. ipython:: python

df = pd.DataFrame(
{'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
Copy link
Member

Choose a reason for hiding this comment

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

same

dflow = df[df.AAA <= 5]
dflow
dfhigh = df[df.AAA > 5]
dfhigh
Copy link
Member

Choose a reason for hiding this comment

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

If those are not being used later, I'd show the result directly, instead of assigning them to a variable first.

def CumRet(x,y):
return x * (1 + y)
def CumRet(x, y):
return x * (1 + y)

def Red(x):
Copy link
Member

Choose a reason for hiding this comment

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

use red, I don't think there is a reason to have these functions named as classes

u'beyer': [99, 102, 103, 103, 88, 100]},
index=[u'Last Gunfighter', u'Last Gunfighter',
u'Last Gunfighter', u'Paynter', u'Paynter',
u'Paynter'])
Copy link
Member

Choose a reason for hiding this comment

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

You can remove all the u'', we'll be supporting Python 3 only very soon.

def gm(aDF,Const):
v = ((((aDF.A+aDF.B)+1).cumprod())-1)*Const
return (aDF.index[0],v.iloc[-1])
def gm(aDF, Const):
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 use df and const instead?

{u'stratifying_var': np.random.uniform(0, 100, 20),
u'price': np.random.normal(100, 5, 20)})
{u'stratifying_var': np.random.uniform(0, 100, 20),
u'price': np.random.normal(100, 5, 20)})
Copy link
Member

Choose a reason for hiding this comment

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

also can remove the u'' here, and below

{'height': [60, 70],
'weight': [100, 140, 180],
'sex': ['Male', 'Female']})
{'height': [60, 70],
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing, but if you want to move this to the previous line, this is how in the previous examples is done.

@datapythonista
Copy link
Member

The CI failed because of doc/source/cookbook.rst:1324:9: E303 too many blank lines (3).

If you can, would be nice to run locally after the fixes:

  • LINT=1 ./ci/code_checks.sh
  • flake8-rst doc/source/cookbook.rst

To see that everything is correct, so we can merge.

@saurav2608
Copy link
Author

The CI failed because of doc/source/cookbook.rst:1324:9: E303 too many blank lines (3).

If you can, would be nice to run locally after the fixes:

* `LINT=1 ./ci/code_checks.sh`

* `flake8-rst doc/source/cookbook.rst`

To see that everything is correct, so we can merge.

Noted your suggestions @datapythonista . I have submitted another PR as this build failed the tests. I will make all these changes and resubmit. I am closing the PR till these are resolved.

@datapythonista
Copy link
Member

You don't need to open new PR for every change.

Just make the changes in the branch you used for the PR, commit and push. The PR will be updated, and it make things much easier for us (and for you I think) this way.

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.

Nice, looks great.

Just one comment. And if you don't mind running flake9-rst doc/source/cookbook.rst to double check that we didn't miss anything, that would be great.

@@ -533,10 +537,10 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to

S = pd.Series([i / 100.0 for i in range(1, 11)])

def CumRet(x, y):
def cumRet(x, y):
Copy link
Member

Choose a reason for hiding this comment

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

cum_ret would be the Pythonic way to name the function.

Can you also replace the names in the places where the function names are used below.

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, added a couple of comments.

@@ -1034,7 +1036,7 @@ You can use the same approach to read all files matching a pattern. Here is an
Finally, this strategy will work with the other ``pd.read_*(...)`` functions described in the :ref:`io docs<io>`.

.. ipython:: python
:suppress:
:verbatim:
Copy link
Member

Choose a reason for hiding this comment

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

What does :verbatim: does? I assume the suppress made those not appear in the rendered docs, is that still the case?

Copy link
Author

Choose a reason for hiding this comment

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

:verbatim: prevents execution as well. In this case I think I have made a mistake. The decorator should remain suppress.

return (aDF.index[0],v.iloc[-1])
def gm(df, const):
v = ((((df.A + df.B) + 1).cumprod()) - 1) * const
return (v.iloc[-1])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return (v.iloc[-1])
return v.iloc[-1]

@@ -1267,6 +1324,7 @@ The `method` argument within `DataFrame.corr` can accept a callable in addition
... return cov_ab / std_a / std_b
...
...
...
>>> df = pd.DataFrame(np.random.normal(size=(100, 3)))
...
Copy link
Member

Choose a reason for hiding this comment

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

doesn't seem like this line is required, is it?

Copy link
Author

Choose a reason for hiding this comment

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

This df is reference in a subsequent line.

Copy link
Member

Choose a reason for hiding this comment

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

I mean't the ... in the next line, I don't think that is doing anything.

And I think the validation is failing because of the ... you added before the df = .... Can you remove that and see if that makes the CI green?

Copy link
Author

Choose a reason for hiding this comment

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

Well here goes. One final try. Thanks for the guidance.

@saurav2608
Copy link
Author

The tests pass on my local. Not sure why automate test is failing.

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 good, let's see if the CI ends on green now.

Thanks @saurav2608

doc/source/cookbook.rst Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 22, 2018

Codecov Report

Merging #23837 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23837      +/-   ##
==========================================
+ Coverage   92.29%   92.29%   +<.01%     
==========================================
  Files         161      161              
  Lines       51497    51498       +1     
==========================================
+ Hits        47528    47530       +2     
+ Misses       3969     3968       -1
Flag Coverage Δ
#multiple 90.69% <ø> (ø) ⬆️
#single 42.43% <ø> (+0.1%) ⬆️
Impacted Files Coverage Δ
pandas/io/parsers.py 95.29% <0%> (-0.28%) ⬇️
pandas/io/pytables.py 92.3% <0%> (-0.05%) ⬇️
pandas/core/base.py 97.6% <0%> (-0.01%) ⬇️
pandas/core/indexes/multi.py 95.49% <0%> (-0.01%) ⬇️
pandas/core/generic.py 96.84% <0%> (-0.01%) ⬇️
pandas/core/reshape/pivot.py 96.55% <0%> (ø) ⬆️
pandas/io/json/normalize.py 96.87% <0%> (ø) ⬆️
pandas/io/packers.py 88.08% <0%> (ø) ⬆️
pandas/core/util/hashing.py 98.4% <0%> (ø) ⬆️
pandas/core/strings.py 98.58% <0%> (ø) ⬆️
... and 40 more

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 4f16dff...d57be90. 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.

Thanks for the update @saurav2608, looks great.

@WillAyd?

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Just some nits on imports but rest looks fine. Surprised these weren't caught by linter.

doc/source/cookbook.rst Show resolved Hide resolved
doc/source/cookbook.rst Show resolved Hide resolved
@WillAyd WillAyd merged commit bea9da2 into pandas-dev:master Nov 24, 2018
@WillAyd
Copy link
Member

WillAyd commented Nov 24, 2018

Thanks @saurav2608 !

@saurav2608 saurav2608 deleted the cookbook-doc branch November 24, 2018 19:20
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
Clean Code Style Code style, linting, code_checks Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Fix format of cookbook.rst
3 participants