-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
There was a problem hiding this 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.
doc/source/basics.rst
Outdated
@@ -1,6 +1,6 @@ | |||
.. currentmodule:: pandas | |||
|
|||
.. ipython:: python | |||
.. ipython:: python |
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
I removed the spaces, and it shows these errors :
Did I fix something wrong? |
There was a problem hiding this 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.
doc/source/basics.rst
Outdated
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'))) |
There was a problem hiding this comment.
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.
doc/source/basics.rst
Outdated
@@ -1502,7 +1508,7 @@ Thus, for example, iterating over a DataFrame gives you the column names: | |||
|
|||
.. ipython:: |
There was a problem hiding this comment.
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]
...
doc/source/basics.rst
Outdated
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! |
There was a problem hiding this comment.
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.
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. |
I fixed the missing spaces, adjusted indentation, and removed 'In [0]' from ipython. I also fixed other errors occurred after changes. When I run
|
There was a problem hiding this 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.
doc/source/basics.rst
Outdated
...: print('%s\n%s' % (row_index, row)) | ||
...: | ||
for row_index, row in df.iterrows(): | ||
print('%s\n%s' % (row_index, row)) |
There was a problem hiding this comment.
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')
doc/source/basics.rst
Outdated
C='foo', | ||
D=pd.Timestamp('20010102'), | ||
E=pd.Series([1.0] * 3).astype('float32'), | ||
F=False, G=pd.Series([1] * 3, dtype='int8'))) |
There was a problem hiding this comment.
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?
doc/source/basics.rst
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
doc/source/basics.rst
Outdated
.. ipython:: python | ||
|
||
df = pd.DataFrame( | ||
{'col1': np.random.randn(3), 'col2': np.random.randn(3)}, |
There was a problem hiding this comment.
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)},
doc/source/basics.rst
Outdated
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')))) |
There was a problem hiding this comment.
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'))))
There was a problem hiding this 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
Hi @datapythonista , |
doc/source/basics.rst
Outdated
result | ||
result.loc[:,:,'ItemA'] | ||
result.loc[:, :, 'ItemA'] |
There was a problem hiding this comment.
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'
@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) |
@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 |
yes could remove that whole block is ok. |
@ywpark1 can you remove the whole You can check it here if that makes things easier: http://pandas.pydata.org/pandas-docs/stable/basics.html#applying-with-a-panel |
Thanks for your advice @datapythonista . I was working with local master branch by mistake. |
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. |
@ywpark1 Thanks a lot! |
|
git diff upstream/master -u -- "*.py" | flake8 --diff
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.