Skip to content

DOC: Fix format of basics.rst, following PEP-8 standard #23802

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 10 commits into from
Nov 21, 2018

Conversation

ywpark1
Copy link
Contributor

@ywpark1 ywpark1 commented Nov 20, 2018

I updated the format of doc/source/basics.rst file.
I do not see any errors when I run flake8-rst doc/source/basics.rst.

Please let me know if there are some changes.

@jreback jreback added the Docs label Nov 20, 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.

Will review in detail after the spaces are removed, as they are wrong and they are making the review much more difficult.

@@ -1,6 +1,6 @@
.. currentmodule:: pandas

.. ipython:: python
.. ipython:: python
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we're adding a white space after all directives. Is there a reason, or is it your editor that did those automatically?

Afaik this space is wrong, and they should be removed again.

@codecov
Copy link

codecov bot commented Nov 20, 2018

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23802      +/-   ##
==========================================
+ Coverage   92.28%   92.29%   +<.01%     
==========================================
  Files         161      161              
  Lines       51451    51490      +39     
==========================================
+ Hits        47483    47521      +38     
- Misses       3968     3969       +1
Flag Coverage Δ
#multiple 90.68% <ø> (ø) ⬆️
#single 42.32% <ø> (+0.03%) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/timedeltas.py 89.18% <0%> (-0.08%) ⬇️
pandas/io/parsers.py 95.55% <0%> (-0.02%) ⬇️
pandas/core/arrays/integer.py 95.47% <0%> (-0.02%) ⬇️
pandas/tseries/frequencies.py 97.06% <0%> (-0.02%) ⬇️
pandas/tseries/offsets.py 96.98% <0%> (-0.01%) ⬇️
pandas/core/arrays/period.py 98.44% <0%> (-0.01%) ⬇️
pandas/core/util/hashing.py 98.4% <0%> (ø) ⬆️
pandas/core/sparse/series.py 95.53% <0%> (ø) ⬆️
pandas/core/internals/blocks.py 93.67% <0%> (ø) ⬆️
pandas/tseries/holiday.py 93.17% <0%> (ø) ⬆️
... and 28 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 deb7b4d...9941f0f. Read the comment docs.

@ywpark1
Copy link
Contributor Author

ywpark1 commented Nov 20, 2018

I removed the spaces, and it shows these errors :

doc/source/basics.rst:310:10: E225 missing whitespace around operator
doc/source/basics.rst:6:4: E902 TokenError: EOF in multi-line statement
doc/source/basics.rst:754:4: E402 module level import not at top of file
doc/source/basics.rst:984:4: E402 module level import not at top of file
doc/source/basics.rst:1120:4: E402 module level import not at top of file
doc/source/basics.rst:1992:5: E999 SyntaxError: invalid syntax

Did I fix something wrong?

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. I commented on couple of extra things that I'd fix, but it's a nice improvement.

D = pd.Timestamp('20010102'),
E = pd.Series([1.0]*3).astype('float32'),
F = False,
G = pd.Series([1]*3,dtype='int8')))
F = False, G = pd.Series([1]*3,dtype='int8')))
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 take a look at this example? The indentation doesn't seem right, as well as the spaces around =, and the missing ones around *, and it'd probably make things easier to read having B, C and G in their own line.

@@ -1502,7 +1508,7 @@ Thus, for example, iterating over a DataFrame gives you the column names:

.. ipython::
Copy link
Member

Choose a reason for hiding this comment

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

unless you see a reason for it, I'd make the .. ipython:: a .. ipython:: python as the rest, and would remove the In [0]...

df+df == df*2
(df+df == df*2).all()
df + df == df * 2
(df + df == df * 2).all()

Notice that the boolean DataFrame ``df+df == df*2`` contains some False values!
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 fix the missing spaces here and in the paragraph above. They are not detected as they are not in a code block, but would be nice that they follow pep8 too.

@datapythonista
Copy link
Member

I can't see why you get these errors, but don't worry about them, we can merge all the fixes you made, and check later whether they are caused by a bug in flake-rst or what's wrong.

@ywpark1
Copy link
Contributor Author

ywpark1 commented Nov 20, 2018

I fixed the missing spaces, adjusted indentation, and removed 'In [0]' from ipython.

I also fixed other errors occurred after changes. When I run flake8-rst doc/source/basics.rst, I see only these errors :

doc/source/basics.rst:753:4: E402 module level import not at top of file
doc/source/basics.rst:983:4: E402 module level import not at top of file
doc/source/basics.rst:1119:4: E402 module level import not at top of file
doc/source/basics.rst:2128:6: E402 module level import not at top of file
doc/source/basics.rst:2158:6: E402 module level import not at top of file
doc/source/basics.rst:2178:5: E402 module level import not at top of file
doc/source/basics.rst:2193:5: E402 module level import not at top of file
doc/source/basics.rst:2219:5: E402 module level import not at top of 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.

Nice changes. Added few suggestions on things that I think can be presented more clearly, but looks good.

...: print('%s\n%s' % (row_index, row))
...:
for row_index, row in df.iterrows():
print('%s\n%s' % (row_index, row))
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind changing this by print(row_index, row, sep='\n')

C='foo',
D=pd.Timestamp('20010102'),
E=pd.Series([1.0] * 3).astype('float32'),
F=False, G=pd.Series([1] * 3, dtype='int8')))
Copy link
Member

Choose a reason for hiding this comment

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

could you move G to thenext line for consistency and clairity?

@@ -307,14 +307,13 @@ To evaluate single-element pandas objects in a boolean context, use the method

.. code-block:: python

>>> if df: # noqa: E999
...
>>> if df: # noqa: E999
Copy link
Member

Choose a reason for hiding this comment

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

If the ... is giving problems with the validation I'd replace it by a pass, and we can also remove the noqa comment then.

.. ipython:: python

df = pd.DataFrame(
{'col1': np.random.randn(3), 'col2': np.random.randn(3)},
Copy link
Member

Choose a reason for hiding this comment

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

just a personal opinion here, but I think this style is easier to read:

df = pd.DataFrame({'col1': np.random.randn(3),
                   'col2': np.random.randn(3)},

df2 = pd.DataFrame(dict(A=pd.Series(np.random.randn(8), dtype='float16'),
B=pd.Series(np.random.randn(8)),
C=pd.Series(np.array(
np.random.randn(8), dtype='uint8'))))
Copy link
Member

Choose a reason for hiding this comment

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

I think this is clearer here, and should fit in 79 characters:

C=pd.Series(np.array(np.random.randn(8),
                     dtype='uint8'))))

@datapythonista
Copy link
Member

That's cool, thanks @ywpark1. I think the E402 module level import not at top of file shouldn't be reported by flake8-rst.

I'd add it to the list of flake8-rst errors to ignore in setup.cfg.

@FHaase what do you think?

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 @ywpark1

@ywpark1
Copy link
Contributor Author

ywpark1 commented Nov 21, 2018

Hi @datapythonista ,
If you do not mind, can I try to re-open this Pull Request with the same changes? I touched something wrong in the local git and now it shows bunch of weird commits showing on this Pull Request.

result
result.loc[:,:,'ItemA']
result.loc[:, :, 'ItemA']
Copy link
Member

Choose a reason for hiding this comment

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

I don't directly see how the above changes cause this, but, this example is now failing in the doc build with:

>>>-------------------------------------------------------------------------
Exception in /home/travis/build/pandas-dev/pandas/doc/source/basics.rst at block ending on line 1183
Specify :okexcept: as an option in the ipython:: block to suppress this message

KeyErrorTraceback (most recent call last)

~/build/pandas-dev/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3146             try:
-> 3147                 return self._engine.get_loc(key)
   3148             except KeyError:
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ItemA'

During handling of the above exception, another exception occurred:

KeyErrorTraceback (most recent call last)
<ipython-input-209-ce1c0f9e4a44> in <module>
----> 1 result.loc[:, :, 'ItemA']
~/build/pandas-dev/pandas/pandas/core/indexing.py in __getitem__(self, key)
   1495             except (KeyError, IndexError, AttributeError):
   1496                 pass
-> 1497             return self._getitem_tuple(key)
   1498         else:
   1499             # we by definition only have the 0th axis
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_tuple(self, tup)
    868     def _getitem_tuple(self, tup):
    869         try:
--> 870             return self._getitem_lowerdim(tup)
    871         except IndexingError:
    872             pass
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
    988         for i, key in enumerate(tup):
    989             if is_label_like(key) or isinstance(key, tuple):
--> 990                 section = self._getitem_axis(key, axis=i)
    991 
    992                 # we have yielded a scalar ?
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_axis(self, key, axis)
   1914         # fall thru to straight lookup
   1915         self._validate_key(key, axis)
-> 1916         return self._get_label(key, axis=axis)
   1917 
   1918 
~/build/pandas-dev/pandas/pandas/core/indexing.py in _get_label(self, label, axis)
    146             raise IndexingError('no slices here, handle elsewhere')
    147 
--> 148         return self.obj._xs(label, axis=axis)
    149 
    150     def _get_loc(self, key, axis=None):
~/build/pandas-dev/pandas/pandas/core/panel.py in xs(self, key, axis)
    864         self._consolidate_inplace()
    865         axis_number = self._get_axis_number(axis)
--> 866         new_data = self._data.xs(key, axis=axis_number, copy=False)
    867         result = self._construct_return_type(new_data)
    868         copy = new_data.is_mixed_type
~/build/pandas-dev/pandas/pandas/core/internals/managers.py in xs(self, key, axis, copy, takeable)
    835             loc = key
    836         else:
--> 837             loc = self.axes[axis].get_loc(key)
    838 
    839         slicer = [slice(None, None) for _ in range(self.ndim)]
~/build/pandas-dev/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3147                 return self._engine.get_loc(key)
   3148             except KeyError:
-> 3149                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   3150         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   3151         if indexer.ndim > 1 or indexer.size > 1:
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ItemA'

@jorisvandenbossche
Copy link
Member

If you do not mind, can I try to re-open this Pull Request with the same changes? I touched something wrong in the local git and now it shows bunch of weird commits showing on this Pull Request.

@ywpark1 The diff looks fine now? Or is there still something wrong with it? (and don't worry if there are more commits, they will get squashed when merging, so it is the diff that is important)

@datapythonista
Copy link
Member

@ywpark1 not sure what happened exactly, but in general you don't want to modify anything in a PR once it's been approved (unless you get further feedback).

There is something that will cause some trouble in this case. When working in an issue, you should create a new local git branch. Because you worked directly in master, now you can't work in any other issue until this PR is merged. If you work in something else, you'll have to do it in master and you'll mix things, or you'll have to create a new branch from a modified master, which will contain changes unrelated to the new feature.

We could fix that with a reset, and opening a new PR, but I think it's better to try to merge this, and then you can start again.

@jorisvandenbossche as Panel is deprecated and soon removed, wouldn't make sense to remove that whole block about it from the pandas basics documentation? Besides giving the error, I don't think anyone reading that page should find anything about Panel, they'll learn things that will be removed very soon.

@jreback jreback added this to the 0.24.0 milestone Nov 21, 2018
@jreback
Copy link
Contributor

jreback commented Nov 21, 2018

@jorisvandenbossche as Panel is deprecated and soon removed, wouldn't make sense to remove that whole block about it from the pandas basics documentation? Besides giving the error, I don't think anyone reading that page should find anything about Panel, they'll learn things that will be removed very soon.

yes could remove that whole block is ok.

@jreback jreback removed this from the 0.24.0 milestone Nov 21, 2018
@datapythonista
Copy link
Member

@ywpark1 can you remove the whole Applying with a Panel section please.

You can check it here if that makes things easier: http://pandas.pydata.org/pandas-docs/stable/basics.html#applying-with-a-panel

@ywpark1
Copy link
Contributor Author

ywpark1 commented Nov 21, 2018

Thanks for your advice @datapythonista . I was working with local master branch by mistake.
I will try to work on other issues once this is merged.

@jorisvandenbossche
Copy link
Member

Yes, good idea to just remove that section.

There is still another problem caused by removing this section (an import is missing in another file), but I will merge this and fix that in a separate PR.

@jorisvandenbossche jorisvandenbossche merged commit 161e8f3 into pandas-dev:master Nov 21, 2018
@jorisvandenbossche
Copy link
Member

@ywpark1 Thanks a lot!

@jorisvandenbossche
Copy link
Member

There is still another problem caused by removing this section (an import is missing in another file), but I will merge this and fix that in a separate PR.

#23841

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: Fix format of basics.rst
4 participants