Skip to content

Commit 129bb97

Browse files
datapythonistaPingviinituutti
authored andcommitted
DOC: Fixing more doc warings and wrong .. code-block :: directive (space before colon) (pandas-dev#24650)
1 parent d3f7378 commit 129bb97

13 files changed

+75
-66
lines changed

ci/code_checks.sh

+8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
162162
# invgrep -R --include '*.py' -E '[[:space:]] pytest.raises' pandas/tests
163163
# RET=$(($RET + $?)) ; echo $MSG "DONE"
164164

165+
MSG='Check for wrong space after code-block directive and before colon (".. code-block ::" instead of ".. code-block::")' ; echo $MSG
166+
invgrep -R --include="*.rst" ".. code-block ::" doc/source
167+
RET=$(($RET + $?)) ; echo $MSG "DONE"
168+
169+
MSG='Check for wrong space after ipython directive and before colon (".. ipython ::" instead of ".. ipython::")' ; echo $MSG
170+
invgrep -R --include="*.rst" ".. ipython ::" doc/source
171+
RET=$(($RET + $?)) ; echo $MSG "DONE"
172+
165173
MSG='Check that no file in the repo contains tailing whitespaces' ; echo $MSG
166174
set -o pipefail
167175
if [[ "$AZURE" == "true" ]]; then

doc/source/api/arrays.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Methods
195195

196196
A collection of timedeltas may be stored in a :class:`TimedeltaArray`.
197197

198-
.. autosumarry::
198+
.. autosummary::
199199
:toctree: generated/
200200

201201
arrays.TimedeltaArray

doc/source/dsintro.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Series is ndarray-like
115115
``Series`` acts very similarly to a ``ndarray``, and is a valid argument to most NumPy functions.
116116
However, operations such as slicing will also slice the index.
117117

118-
.. ipython :: python
118+
.. ipython:: python
119119
120120
s[0]
121121
s[:3]
@@ -171,7 +171,7 @@ Series is dict-like
171171
A Series is like a fixed-size dict in that you can get and set values by index
172172
label:
173173

174-
.. ipython :: python
174+
.. ipython:: python
175175
176176
s['a']
177177
s['e'] = 12.

doc/source/indexing.rst

+14-13
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,9 @@ Selecting Random Samples
743743

744744
A random selection of rows or columns from a Series, DataFrame, or Panel with the :meth:`~DataFrame.sample` method. The method will sample rows by default, and accepts a specific number of rows/columns to return, or a fraction of rows.
745745

746-
.. ipython :: python
746+
.. ipython:: python
747747
748-
s = pd.Series([0,1,2,3,4,5])
748+
s = pd.Series([0, 1, 2, 3, 4, 5])
749749
750750
# When no arguments are passed, returns 1 row.
751751
s.sample()
@@ -759,9 +759,9 @@ A random selection of rows or columns from a Series, DataFrame, or Panel with th
759759
By default, ``sample`` will return each row at most once, but one can also sample with replacement
760760
using the ``replace`` option:
761761

762-
.. ipython :: python
762+
.. ipython:: python
763763
764-
s = pd.Series([0,1,2,3,4,5])
764+
s = pd.Series([0, 1, 2, 3, 4, 5])
765765
766766
# Without replacement (default):
767767
s.sample(n=6, replace=False)
@@ -774,9 +774,9 @@ By default, each row has an equal probability of being selected, but if you want
774774
to have different probabilities, you can pass the ``sample`` function sampling weights as
775775
``weights``. These weights can be a list, a NumPy array, or a Series, but they must be of the same length as the object you are sampling. Missing values will be treated as a weight of zero, and inf values are not allowed. If weights do not sum to 1, they will be re-normalized by dividing all weights by the sum of the weights. For example:
776776

777-
.. ipython :: python
777+
.. ipython:: python
778778
779-
s = pd.Series([0,1,2,3,4,5])
779+
s = pd.Series([0, 1, 2, 3, 4, 5])
780780
example_weights = [0, 0, 0.2, 0.2, 0.2, 0.4]
781781
s.sample(n=3, weights=example_weights)
782782
@@ -788,23 +788,24 @@ When applied to a DataFrame, you can use a column of the DataFrame as sampling w
788788
(provided you are sampling rows and not columns) by simply passing the name of the column
789789
as a string.
790790

791-
.. ipython :: python
791+
.. ipython:: python
792792
793-
df2 = pd.DataFrame({'col1':[9,8,7,6], 'weight_column':[0.5, 0.4, 0.1, 0]})
794-
df2.sample(n = 3, weights = 'weight_column')
793+
df2 = pd.DataFrame({'col1': [9, 8, 7, 6],
794+
'weight_column': [0.5, 0.4, 0.1, 0]})
795+
df2.sample(n=3, weights='weight_column')
795796
796797
``sample`` also allows users to sample columns instead of rows using the ``axis`` argument.
797798

798-
.. ipython :: python
799+
.. ipython:: python
799800
800-
df3 = pd.DataFrame({'col1':[1,2,3], 'col2':[2,3,4]})
801+
df3 = pd.DataFrame({'col1': [1, 2, 3], 'col2': [2, 3, 4]})
801802
df3.sample(n=1, axis=1)
802803
803804
Finally, one can also set a seed for ``sample``'s random number generator using the ``random_state`` argument, which will accept either an integer (as a seed) or a NumPy RandomState object.
804805

805-
.. ipython :: python
806+
.. ipython:: python
806807
807-
df4 = pd.DataFrame({'col1':[1,2,3], 'col2':[2,3,4]})
808+
df4 = pd.DataFrame({'col1': [1, 2, 3], 'col2': [2, 3, 4]})
808809
809810
# With a given seed, the sample will always draw the same rows.
810811
df4.sample(n=2, random_state=2)

doc/source/io.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ Duplicate names parsing
578578
If the file or header contains duplicate names, pandas will by default
579579
distinguish between them so as to prevent overwriting data:
580580

581-
.. ipython :: python
581+
.. ipython:: python
582582
583583
data = ('a,b,a\n'
584584
'0,1,2\n'
@@ -590,7 +590,7 @@ which modifies a series of duplicate columns 'X', ..., 'X' to become
590590
'X', 'X.1', ..., 'X.N'. If ``mangle_dupe_cols=False``, duplicate data can
591591
arise:
592592

593-
.. code-block :: python
593+
.. code-block:: ipython
594594
595595
In [2]: data = 'a,b,a\n0,1,2\n3,4,5'
596596
In [3]: pd.read_csv(StringIO(data), mangle_dupe_cols=False)
@@ -602,7 +602,7 @@ arise:
602602
To prevent users from encountering this problem with duplicate data, a ``ValueError``
603603
exception is raised if ``mangle_dupe_cols != True``:
604604

605-
.. code-block :: python
605+
.. code-block:: ipython
606606
607607
In [2]: data = 'a,b,a\n0,1,2\n3,4,5'
608608
In [3]: pd.read_csv(StringIO(data), mangle_dupe_cols=False)

doc/source/whatsnew/v0.12.0.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ I/O Enhancements
191191

192192
You can use ``pd.read_html()`` to read the output from ``DataFrame.to_html()`` like so
193193

194-
.. ipython :: python
194+
.. ipython:: python
195195
:okwarning:
196196
197197
df = pd.DataFrame({'a': range(3), 'b': list('abc')})
@@ -296,7 +296,7 @@ Other Enhancements
296296

297297
For example you can do
298298

299-
.. ipython :: python
299+
.. ipython:: python
300300
301301
df = pd.DataFrame({'a': list('ab..'), 'b': [1, 2, 3, 4]})
302302
df.replace(regex=r'\s*\.\s*', value=np.nan)
@@ -306,7 +306,7 @@ Other Enhancements
306306

307307
Regular string replacement still works as expected. For example, you can do
308308

309-
.. ipython :: python
309+
.. ipython:: python
310310
311311
df.replace('.', np.nan)
312312

doc/source/whatsnew/v0.15.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ Other:
10151015

10161016
.. ipython:: python
10171017
1018-
business_dates = date_range(start='4/1/2014', end='6/30/2014', freq='B')
1018+
business_dates = pd.date_range(start='4/1/2014', end='6/30/2014', freq='B')
10191019
df = pd.DataFrame(1, index=business_dates, columns=['a', 'b'])
10201020
# get the first, 4th, and last date index for each month
10211021
df.groupby([df.index.year, df.index.month]).nth([0, 3, -1])

doc/source/whatsnew/v0.16.0.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ to be inserted (for example, a ``Series`` or NumPy array), or a function
5151
of one argument to be called on the ``DataFrame``. The new values are inserted,
5252
and the entire DataFrame (with all original and new columns) is returned.
5353

54-
.. ipython :: python
54+
.. ipython:: python
5555
5656
iris = pd.read_csv('data/iris.data')
5757
iris.head()
@@ -61,10 +61,10 @@ and the entire DataFrame (with all original and new columns) is returned.
6161
Above was an example of inserting a precomputed value. We can also pass in
6262
a function to be evaluated.
6363

64-
.. ipython :: python
64+
.. ipython:: python
6565
66-
iris.assign(sepal_ratio = lambda x: (x['SepalWidth'] /
67-
x['SepalLength'])).head()
66+
iris.assign(sepal_ratio=lambda x: (x['SepalWidth']
67+
/ x['SepalLength'])).head()
6868
6969
The power of ``assign`` comes when used in chains of operations. For example,
7070
we can limit the DataFrame to just those with a Sepal Length greater than 5,

doc/source/whatsnew/v0.16.1.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ total number or rows or columns. It also has options for sampling with or withou
181181
for passing in a column for weights for non-uniform sampling, and for setting seed values to
182182
facilitate replication. (:issue:`2419`)
183183

184-
.. ipython :: python
184+
.. ipython:: python
185185
186-
example_series = Series([0,1,2,3,4,5])
186+
example_series = pd.Series([0, 1, 2, 3, 4, 5])
187187
188188
# When no arguments are passed, returns 1
189189
example_series.sample()
@@ -207,9 +207,10 @@ facilitate replication. (:issue:`2419`)
207207
When applied to a DataFrame, one may pass the name of a column to specify sampling weights
208208
when sampling from rows.
209209

210-
.. ipython :: python
210+
.. ipython:: python
211211
212-
df = DataFrame({'col1':[9,8,7,6], 'weight_column':[0.5, 0.4, 0.1, 0]})
212+
df = pd.DataFrame({'col1': [9, 8, 7, 6],
213+
'weight_column': [0.5, 0.4, 0.1, 0]})
213214
df.sample(n=3, weights='weight_column')
214215
215216

doc/source/whatsnew/v0.17.0.rst

+27-28
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ The new implementation allows for having a single-timezone across all rows, with
8484

8585
.. ipython:: python
8686
87-
df = DataFrame({'A': date_range('20130101', periods=3),
88-
'B': date_range('20130101', periods=3, tz='US/Eastern'),
89-
'C': date_range('20130101', periods=3, tz='CET')})
87+
df = pd.DataFrame({'A': pd.date_range('20130101', periods=3),
88+
'B': pd.date_range('20130101', periods=3, tz='US/Eastern'),
89+
'C': pd.date_range('20130101', periods=3, tz='CET')})
9090
df
9191
df.dtypes
9292
@@ -442,17 +442,18 @@ Other enhancements
442442
443443
- Added a ``DataFrame.round`` method to round the values to a variable number of decimal places (:issue:`10568`).
444444

445-
.. ipython :: python
445+
.. ipython:: python
446446
447-
df = pd.DataFrame(np.random.random([3, 3]), columns=['A', 'B', 'C'],
448-
index=['first', 'second', 'third'])
447+
df = pd.DataFrame(np.random.random([3, 3]),
448+
columns=['A', 'B', 'C'],
449+
index=['first', 'second', 'third'])
449450
df
450451
df.round(2)
451452
df.round({'A': 0, 'C': 2})
452453
453454
- ``drop_duplicates`` and ``duplicated`` now accept a ``keep`` keyword to target first, last, and all duplicates. The ``take_last`` keyword is deprecated, see :ref:`here <whatsnew_0170.deprecations>` (:issue:`6511`, :issue:`8505`)
454455

455-
.. ipython :: python
456+
.. ipython:: python
456457
457458
s = pd.Series(['A', 'B', 'C', 'A', 'B', 'D'])
458459
s.drop_duplicates()
@@ -630,13 +631,13 @@ Of course you can coerce this as well.
630631

631632
.. ipython:: python
632633
633-
to_datetime(['2009-07-31', 'asd'], errors='coerce')
634+
pd.to_datetime(['2009-07-31', 'asd'], errors='coerce')
634635
635636
To keep the previous behavior, you can use ``errors='ignore'``:
636637

637638
.. ipython:: python
638639
639-
to_datetime(['2009-07-31', 'asd'], errors='ignore')
640+
pd.to_datetime(['2009-07-31', 'asd'], errors='ignore')
640641
641642
Furthermore, ``pd.to_timedelta`` has gained a similar API, of ``errors='raise'|'ignore'|'coerce'``, and the ``coerce`` keyword
642643
has been deprecated in favor of ``errors='coerce'``.
@@ -655,13 +656,13 @@ Previous Behavior:
655656

656657
.. code-block:: ipython
657658
658-
In [1]: Timestamp('2012Q2')
659+
In [1]: pd.Timestamp('2012Q2')
659660
Traceback
660661
...
661662
ValueError: Unable to parse 2012Q2
662663
663664
# Results in today's date.
664-
In [2]: Timestamp('2014')
665+
In [2]: pd.Timestamp('2014')
665666
Out [2]: 2014-08-12 00:00:00
666667
667668
v0.17.0 can parse them as below. It works on ``DatetimeIndex`` also.
@@ -670,9 +671,9 @@ New Behavior:
670671

671672
.. ipython:: python
672673
673-
Timestamp('2012Q2')
674-
Timestamp('2014')
675-
DatetimeIndex(['2012Q2', '2014'])
674+
pd.Timestamp('2012Q2')
675+
pd.Timestamp('2014')
676+
pd.DatetimeIndex(['2012Q2', '2014'])
676677
677678
.. note::
678679

@@ -681,8 +682,8 @@ New Behavior:
681682
.. ipython:: python
682683
683684
import pandas.tseries.offsets as offsets
684-
Timestamp.now()
685-
Timestamp.now() + offsets.DateOffset(years=1)
685+
pd.Timestamp.now()
686+
pd.Timestamp.now() + offsets.DateOffset(years=1)
686687
687688
Changes to Index Comparisons
688689
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -739,7 +740,7 @@ Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to compar
739740

740741
.. ipython:: python
741742
742-
s = Series(range(3))
743+
s = pd.Series(range(3))
743744
s.iloc[1] = None
744745
s
745746
@@ -807,11 +808,6 @@ Previous Behavior:
807808
808809
New Behavior:
809810

810-
.. ipython:: python
811-
:suppress:
812-
813-
import os
814-
815811
.. ipython:: python
816812
817813
df_with_missing.to_hdf('file.h5',
@@ -824,6 +820,7 @@ New Behavior:
824820
.. ipython:: python
825821
:suppress:
826822
823+
import os
827824
os.remove('file.h5')
828825
829826
See the :ref:`docs <io.hdf5>` for more details.
@@ -876,7 +873,7 @@ Changes to ``Categorical.unique``
876873
- unordered category: values and categories are sorted by appearance order.
877874
- ordered category: values are sorted by appearance order, categories keep existing order.
878875

879-
.. ipython :: python
876+
.. ipython:: python
880877
881878
cat = pd.Categorical(['C', 'A', 'B', 'C'],
882879
categories=['A', 'B', 'C'],
@@ -899,7 +896,7 @@ an integer, resulting in ``header=0`` for ``False`` and ``header=1`` for ``True`
899896

900897
A ``bool`` input to ``header`` will now raise a ``TypeError``
901898

902-
.. code-block :: python
899+
.. code-block:: ipython
903900
904901
In [29]: df = pd.read_csv('data.csv', header=False)
905902
TypeError: Passing a bool to header is invalid. Use header=None for no header or
@@ -984,10 +981,12 @@ Removal of prior version deprecations/changes
984981
- Removal of ``colSpace`` parameter from ``DataFrame.to_string()``, in favor of ``col_space``, circa 0.8.0 version.
985982
- Removal of automatic time-series broadcasting (:issue:`2304`)
986983

987-
.. ipython :: python
984+
.. ipython:: python
988985
989986
np.random.seed(1234)
990-
df = DataFrame(np.random.randn(5,2),columns=list('AB'),index=date_range('20130101',periods=5))
987+
df = DataFrame(np.random.randn(5, 2),
988+
columns=list('AB'),
989+
index=date_range('20130101', periods=5))
991990
df
992991
993992
Previously
@@ -1008,9 +1007,9 @@ Removal of prior version deprecations/changes
10081007
10091008
Current
10101009

1011-
.. ipython :: python
1010+
.. ipython:: python
10121011
1013-
df.add(df.A,axis='index')
1012+
df.add(df.A, axis='index')
10141013
10151014
10161015
- Remove ``table`` keyword in ``HDFStore.put/append``, in favor of using ``format=`` (:issue:`4645`)

0 commit comments

Comments
 (0)