Skip to content

Commit

Permalink
DOC/CI: Add linting to rst files, and fix issues (pandas-dev#23381)
Browse files Browse the repository at this point in the history
  • Loading branch information
FHaase authored and Pingviinituutti committed Feb 28, 2019
1 parent 2491a30 commit aed3852
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 136 deletions.
10 changes: 10 additions & 0 deletions ci/code_checks.sh
Expand Up @@ -44,6 +44,13 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
flake8 pandas/_libs --filename=*.pxi.in,*.pxd --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
RET=$(($RET + $?)) ; echo $MSG "DONE"

echo "flake8-rst --version"
flake8-rst --version

MSG='Linting code-blocks in .rst documentation' ; echo $MSG
flake8-rst doc/source --filename=*.rst
RET=$(($RET + $?)) ; echo $MSG "DONE"

# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
# it doesn't make a difference, but we want to be internally consistent.
# Note: this grep pattern is (intended to be) equivalent to the python
Expand All @@ -64,6 +71,9 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime
RET=$(($RET + $?)) ; echo $MSG "DONE"

echo "isort --version-number"
isort --version-number

# Imports - Check formatting using isort see setup.cfg for settings
MSG='Check import format using isort ' ; echo $MSG
isort --recursive --check-only pandas
Expand Down
1 change: 1 addition & 0 deletions ci/deps/travis-36.yaml
Expand Up @@ -9,6 +9,7 @@ dependencies:
- fastparquet
- flake8>=3.5
- flake8-comprehensions
- flake8-rst
- gcsfs
- geopandas
- html5lib
Expand Down
1 change: 1 addition & 0 deletions ci/environment-dev.yaml
Expand Up @@ -7,6 +7,7 @@ dependencies:
- NumPy
- flake8
- flake8-comprehensions
- flake8-rst
- hypothesis>=3.58.0
- isort
- moto
Expand Down
1 change: 1 addition & 0 deletions ci/requirements_dev.txt
Expand Up @@ -4,6 +4,7 @@ Cython>=0.28.2
NumPy
flake8
flake8-comprehensions
flake8-rst
hypothesis>=3.58.0
isort
moto
Expand Down
56 changes: 28 additions & 28 deletions doc/source/10min.rst
Expand Up @@ -45,7 +45,7 @@ a default integer index:

.. ipython:: python
s = pd.Series([1,3,5,np.nan,6,8])
s = pd.Series([1, 3, 5, np.nan, 6, 8])
s
Creating a :class:`DataFrame` by passing a NumPy array, with a datetime index
Expand All @@ -62,12 +62,12 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s

.. ipython:: python
df2 = pd.DataFrame({ 'A' : 1.,
'B' : pd.Timestamp('20130102'),
'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
'D' : np.array([3] * 4,dtype='int32'),
'E' : pd.Categorical(["test","train","test","train"]),
'F' : 'foo' })
df2 = pd.DataFrame({'A': 1.,
'B': pd.Timestamp('20130102'),
'C': pd.Series(1, index=list(range(4)),dtype='float32'),
'D': np.array([3] * 4, dtype='int32'),
'E': pd.Categorical(["test", "train", "test", "train"]),
'F': 'foo'})
df2
The columns of the resulting ``DataFrame`` have different
Expand Down Expand Up @@ -283,9 +283,9 @@ Using the :func:`~Series.isin` method for filtering:
.. ipython:: python
df2 = df.copy()
df2['E'] = ['one', 'one','two','three','four','three']
df2['E'] = ['one', 'one', 'two', 'three', 'four', 'three']
df2
df2[df2['E'].isin(['two','four'])]
df2[df2['E'].isin(['two', 'four'])]
Setting
~~~~~~~
Expand All @@ -295,7 +295,7 @@ by the indexes.

.. ipython:: python
s1 = pd.Series([1,2,3,4,5,6], index=pd.date_range('20130102', periods=6))
s1 = pd.Series([1, 2, 3, 4, 5, 6], index=pd.date_range('20130102', periods=6))
s1
df['F'] = s1
Expand Down Expand Up @@ -394,7 +394,7 @@ In addition, pandas automatically broadcasts along the specified dimension.

.. ipython:: python
s = pd.Series([1,3,5,np.nan,6,8], index=dates).shift(2)
s = pd.Series([1, 3, 5, np.nan, 6, 8], index=dates).shift(2)
s
df.sub(s, axis='index')
Expand Down Expand Up @@ -492,7 +492,7 @@ section.

.. ipython:: python
df = pd.DataFrame(np.random.randn(8, 4), columns=['A','B','C','D'])
df = pd.DataFrame(np.random.randn(8, 4), columns=['A', 'B', 'C', 'D'])
df
s = df.iloc[3]
df.append(s, ignore_index=True)
Expand All @@ -512,12 +512,12 @@ See the :ref:`Grouping section <groupby>`.

.. ipython:: python
df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B' : ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C' : np.random.randn(8),
'D' : np.random.randn(8)})
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B': ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})
df
Grouping and then applying the :meth:`~DataFrame.sum` function to the resulting
Expand All @@ -532,7 +532,7 @@ apply the ``sum`` function.

.. ipython:: python
df.groupby(['A','B']).sum()
df.groupby(['A', 'B']).sum()
Reshaping
---------
Expand Down Expand Up @@ -578,11 +578,11 @@ See the section on :ref:`Pivot Tables <reshaping.pivot>`.

.. ipython:: python
df = pd.DataFrame({'A' : ['one', 'one', 'two', 'three'] * 3,
'B' : ['A', 'B', 'C'] * 4,
'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
'D' : np.random.randn(12),
'E' : np.random.randn(12)})
df = pd.DataFrame({'A': ['one', 'one', 'two', 'three'] * 3,
'B': ['A', 'B', 'C'] * 4,
'C': ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
'D': np.random.randn(12),
'E': np.random.randn(12)})
df
We can produce pivot tables from this data very easily:
Expand Down Expand Up @@ -653,7 +653,7 @@ pandas can include categorical data in a ``DataFrame``. For full docs, see the

.. ipython:: python
df = pd.DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
df = pd.DataFrame({"id":[1, 2, 3, 4, 5, 6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
Convert the raw grades to a categorical data type.

Expand Down Expand Up @@ -753,13 +753,13 @@ Writing to a HDF5 Store.

.. ipython:: python
df.to_hdf('foo.h5','df')
df.to_hdf('foo.h5', 'df')
Reading from a HDF5 Store.

.. ipython:: python
pd.read_hdf('foo.h5','df')
pd.read_hdf('foo.h5', 'df')
.. ipython:: python
:suppress:
Expand Down Expand Up @@ -796,7 +796,7 @@ If you are attempting to perform an operation you might see an exception like:
.. code-block:: python
>>> if pd.Series([False, True, False]):
print("I was true")
... print("I was true")
Traceback
...
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
Expand Down
10 changes: 5 additions & 5 deletions doc/source/advanced.rst
Expand Up @@ -318,13 +318,13 @@ As usual, **both sides** of the slicers are included as this is label indexing.

.. code-block:: python
df.loc[(slice('A1','A3'),.....), :]
df.loc[(slice('A1', 'A3'), ...), :] # noqa: E999
  You should **not** do this:

.. code-block:: python
df.loc[(slice('A1','A3'),.....)]
df.loc[(slice('A1', 'A3'), ...)] # noqa: E999
.. ipython:: python
Expand Down Expand Up @@ -532,7 +532,7 @@ used to move the values from the ``MultiIndex`` to a column.
.. ipython:: python
df.rename_axis(index=['abc', 'def'])
Note that the columns of a ``DataFrame`` are an index, so that using
``rename_axis`` with the ``columns`` argument will change the name of that
index.
Expand Down Expand Up @@ -779,7 +779,7 @@ values **not** in the categories, similarly to how you can reindex **any** panda
Reshaping and Comparison operations on a ``CategoricalIndex`` must have the same categories
or a ``TypeError`` will be raised.

.. code-block:: python
.. code-block:: ipython
In [9]: df3 = pd.DataFrame({'A' : np.arange(6),
'B' : pd.Series(list('aabbca')).astype('category')})
Expand Down Expand Up @@ -1071,7 +1071,7 @@ On the other hand, if the index is not monotonic, then both slice bounds must be
# OK because 2 and 4 are in the index
df.loc[2:4, :]
.. code-block:: python
.. code-block:: ipython
# 0 is not in the index
In [9]: df.loc[0:4, :]
Expand Down
11 changes: 5 additions & 6 deletions doc/source/basics.rst
Expand Up @@ -306,8 +306,8 @@ To evaluate single-element pandas objects in a boolean context, use the method

.. code-block:: python
>>> if df:
...
>>> if df: # noqa: E999
...
Or

Expand All @@ -317,7 +317,7 @@ To evaluate single-element pandas objects in a boolean context, use the method
These will both raise errors, as you are trying to compare multiple values.

.. code-block:: python
.. code-block:: python-traceback
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
Expand Down Expand Up @@ -732,9 +732,8 @@ with the equivalent
.. code-block:: python
>>> (df.pipe(h)
.pipe(g, arg1=1)
.pipe(f, arg2=2, arg3=3)
)
... .pipe(g, arg1=1)
... .pipe(f, arg2=2, arg3=3))
Pandas encourages the second style, which is known as method chaining.
``pipe`` makes it easy to use your own or another library's functions
Expand Down
2 changes: 1 addition & 1 deletion doc/source/comparison_with_sas.rst
Expand Up @@ -744,7 +744,7 @@ XPORT is a relatively limited format and the parsing of it is not as
optimized as some of the other pandas readers. An alternative way
to interop data between SAS and pandas is to serialize to csv.

.. code-block:: python
.. code-block:: ipython
# version 0.17, 10M rows
Expand Down
18 changes: 12 additions & 6 deletions doc/source/contributing.rst
Expand Up @@ -792,15 +792,15 @@ Transitioning to ``pytest``
.. code-block:: python
class TestReallyCoolFeature(object):
....
pass
Going forward, we are moving to a more *functional* style using the `pytest <http://docs.pytest.org/en/latest/>`__ framework, which offers a richer testing
framework that will facilitate testing and developing. Thus, instead of writing test classes, we will write test functions like this:

.. code-block:: python
def test_really_cool_feature():
....
pass
Using ``pytest``
~~~~~~~~~~~~~~~~
Expand All @@ -825,25 +825,30 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
import pandas as pd
from pandas.util import testing as tm
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
def test_dtypes(dtype):
assert str(np.dtype(dtype)) == dtype
@pytest.mark.parametrize('dtype', ['float32',
pytest.param('int16', marks=pytest.mark.skip),
pytest.param('int32',
marks=pytest.mark.xfail(reason='to show how it works'))])
@pytest.mark.parametrize(
'dtype', ['float32', pytest.param('int16', marks=pytest.mark.skip),
pytest.param('int32', marks=pytest.mark.xfail(
reason='to show how it works'))])
def test_mark(dtype):
assert str(np.dtype(dtype)) == 'float32'
@pytest.fixture
def series():
return pd.Series([1, 2, 3])
@pytest.fixture(params=['int8', 'int16', 'int32', 'int64'])
def dtype(request):
return request.param
def test_series(series, dtype):
result = series.astype(dtype)
assert result.dtype == dtype
Expand Down Expand Up @@ -912,6 +917,7 @@ for details <https://hypothesis.readthedocs.io/en/latest/index.html>`_.
st.lists(any_json_value), st.dictionaries(st.text(), any_json_value)
))
@given(value=any_json_value)
def test_json_roundtrip(value):
result = json.loads(json.dumps(value))
Expand Down

0 comments on commit aed3852

Please sign in to comment.