Skip to content

Commit 057ce10

Browse files
committed
Format all rst files
1 parent 8ec3ec0 commit 057ce10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1550
-1352
lines changed

doc/source/development/contributing_codebase.rst

+26-14
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ the ``pandas.util._decorators.deprecate``:
118118
119119
from pandas.util._decorators import deprecate
120120
121-
deprecate('old_func', 'new_func', '1.1.0')
121+
deprecate("old_func", "new_func", "1.1.0")
122122
123123
Otherwise, you need to do it manually:
124124

@@ -135,7 +135,7 @@ Otherwise, you need to do it manually:
135135
Use new_func instead.
136136
"""
137137
warnings.warn(
138-
'Use new_func instead.',
138+
"Use new_func instead.",
139139
FutureWarning,
140140
stacklevel=find_stack_level(),
141141
)
@@ -179,6 +179,7 @@ The appropriate way to annotate this would be as follows
179179
180180
str_type = str
181181
182+
182183
class SomeClass2:
183184
str: str_type = None
184185
@@ -190,8 +191,8 @@ In some cases you may be tempted to use ``cast`` from the typing module when you
190191
191192
from pandas.core.dtypes.common import is_number
192193
193-
def cannot_infer_bad(obj: Union[str, int, float]):
194194
195+
def cannot_infer_bad(obj: Union[str, int, float]):
195196
if is_number(obj):
196197
...
197198
else: # Reasonably only str objects would reach this but...
@@ -203,7 +204,6 @@ The limitation here is that while a human can reasonably understand that ``is_nu
203204
.. code-block:: python
204205
205206
def cannot_infer_good(obj: Union[str, int, float]):
206-
207207
if isinstance(obj, str):
208208
return obj.upper()
209209
else:
@@ -222,6 +222,7 @@ For example, quite a few functions in pandas accept a ``dtype`` argument. This c
222222
223223
from pandas._typing import Dtype
224224
225+
225226
def as_type(dtype: Dtype) -> ...:
226227
...
227228
@@ -428,6 +429,7 @@ be located.
428429
import pandas as pd
429430
import pandas._testing as tm
430431
432+
431433
def test_getitem_listlike_of_ints():
432434
ser = pd.Series(range(5))
433435
@@ -635,25 +637,29 @@ as a comment to a new test.
635637
import pandas as pd
636638
637639
638-
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
640+
@pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"])
639641
def test_dtypes(dtype):
640642
assert str(np.dtype(dtype)) == dtype
641643
642644
643645
@pytest.mark.parametrize(
644-
'dtype', ['float32', pytest.param('int16', marks=pytest.mark.skip),
645-
pytest.param('int32', marks=pytest.mark.xfail(
646-
reason='to show how it works'))])
646+
"dtype",
647+
[
648+
"float32",
649+
pytest.param("int16", marks=pytest.mark.skip),
650+
pytest.param("int32", marks=pytest.mark.xfail(reason="to show how it works")),
651+
],
652+
)
647653
def test_mark(dtype):
648-
assert str(np.dtype(dtype)) == 'float32'
654+
assert str(np.dtype(dtype)) == "float32"
649655
650656
651657
@pytest.fixture
652658
def series():
653659
return pd.Series([1, 2, 3])
654660
655661
656-
@pytest.fixture(params=['int8', 'int16', 'int32', 'int64'])
662+
@pytest.fixture(params=["int8", "int16", "int32", "int64"])
657663
def dtype(request):
658664
return request.param
659665
@@ -722,10 +728,16 @@ for details <https://hypothesis.readthedocs.io/en/latest/index.html>`_.
722728
import json
723729
from hypothesis import given, strategies as st
724730
725-
any_json_value = st.deferred(lambda: st.one_of(
726-
st.none(), st.booleans(), st.floats(allow_nan=False), st.text(),
727-
st.lists(any_json_value), st.dictionaries(st.text(), any_json_value)
728-
))
731+
any_json_value = st.deferred(
732+
lambda: st.one_of(
733+
st.none(),
734+
st.booleans(),
735+
st.floats(allow_nan=False),
736+
st.text(),
737+
st.lists(any_json_value),
738+
st.dictionaries(st.text(), any_json_value),
739+
)
740+
)
729741
730742
731743
@given(value=any_json_value)

doc/source/development/contributing_docstring.rst

+3-7
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ backticks. The following are considered inline code:
137137
.. code-block:: python
138138
139139
def func():
140-
141140
"""Some function.
142141
143142
With several mistakes in the docstring.
@@ -297,7 +296,7 @@ would be used, then we will specify "str, int or None, default None".
297296
.. code-block:: python
298297
299298
class Series:
300-
def plot(self, kind, color='blue', **kwargs):
299+
def plot(self, kind, color="blue", **kwargs):
301300
"""
302301
Generate a plot.
303302
@@ -463,6 +462,7 @@ With more than one value:
463462
464463
import string
465464
465+
466466
def random_letters():
467467
"""
468468
Generate and return a sequence of random letters.
@@ -478,8 +478,7 @@ With more than one value:
478478
String of random letters.
479479
"""
480480
length = np.random.randint(1, 10)
481-
letters = ''.join(np.random.choice(string.ascii_lowercase)
482-
for i in range(length))
481+
letters = "".join(np.random.choice(string.ascii_lowercase) for i in range(length))
483482
return length, letters
484483
485484
If the method yields its value:
@@ -628,7 +627,6 @@ A simple example could be:
628627
.. code-block:: python
629628
630629
class Series:
631-
632630
def head(self, n=5):
633631
"""
634632
Return the first elements of the Series.
@@ -724,7 +722,6 @@ positional arguments ``head(3)``.
724722
.. code-block:: python
725723
726724
class Series:
727-
728725
def mean(self):
729726
"""
730727
Compute the mean of the input.
@@ -737,7 +734,6 @@ positional arguments ``head(3)``.
737734
"""
738735
pass
739736
740-
741737
def fillna(self, value):
742738
"""
743739
Replace missing values by ``value``.

doc/source/development/extending.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ Below is an example to define two original properties, "internal_cache" as a tem
408408
.. code-block:: python
409409
410410
class SubclassedDataFrame2(pd.DataFrame):
411-
412411
# temporary properties
413412
_internal_names = pd.DataFrame._internal_names + ["internal_cache"]
414413
_internal_names_set = set(_internal_names)
@@ -526,6 +525,7 @@ The ``__pandas_priority__`` of :class:`DataFrame`, :class:`Series`, and :class:`
526525
# return `self` and not the addition for simplicity
527526
return self
528527
528+
529529
custom = CustomList()
530530
series = pd.Series([1, 2, 3])
531531

doc/source/development/maintaining.rst

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ create a file ``t.py`` in your pandas directory, which contains
144144
.. code-block:: python
145145
146146
import pandas as pd
147+
147148
assert pd.Series([1, 1]).sum() == 2
148149
149150
and then run::

doc/source/getting_started/comparison/comparison_with_spreadsheets.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,7 @@ The equivalent in pandas:
427427

428428
.. ipython:: python
429429
430-
pd.pivot_table(
431-
tips, values="tip", index=["size"], columns=["sex"], aggfunc=np.average
432-
)
430+
pd.pivot_table(tips, values="tip", index=["size"], columns=["sex"], aggfunc=np.average)
433431
434432
435433
Adding a row
@@ -440,8 +438,9 @@ Assuming we are using a :class:`~pandas.RangeIndex` (numbered ``0``, ``1``, etc.
440438
.. ipython:: python
441439
442440
df
443-
new_row = pd.DataFrame([["E", 51, True]],
444-
columns=["class", "student_count", "all_pass"])
441+
new_row = pd.DataFrame(
442+
[["E", 51, True]], columns=["class", "student_count", "all_pass"]
443+
)
445444
pd.concat([df, new_row])
446445
447446

doc/source/getting_started/comparison/comparison_with_sql.rst

+3-9
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ UNION
331331
df1 = pd.DataFrame(
332332
{"city": ["Chicago", "San Francisco", "New York City"], "rank": range(1, 4)}
333333
)
334-
df2 = pd.DataFrame(
335-
{"city": ["Chicago", "Boston", "Los Angeles"], "rank": [1, 4, 5]}
336-
)
334+
df2 = pd.DataFrame({"city": ["Chicago", "Boston", "Los Angeles"], "rank": [1, 4, 5]})
337335
338336
.. code-block:: sql
339337
@@ -433,9 +431,7 @@ Top n rows per group
433431
434432
(
435433
tips.assign(
436-
rn=tips.sort_values(["total_bill"], ascending=False)
437-
.groupby(["day"])
438-
.cumcount()
434+
rn=tips.sort_values(["total_bill"], ascending=False).groupby(["day"]).cumcount()
439435
+ 1
440436
)
441437
.query("rn < 3")
@@ -448,9 +444,7 @@ the same using ``rank(method='first')`` function
448444
449445
(
450446
tips.assign(
451-
rnk=tips.groupby(["day"])["total_bill"].rank(
452-
method="first", ascending=False
453-
)
447+
rnk=tips.groupby(["day"])["total_bill"].rank(method="first", ascending=False)
454448
)
455449
.query("rnk < 3")
456450
.sort_values(["day", "rnk"])

doc/source/getting_started/comparison/includes/time_date.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
tips["date1_year"] = tips["date1"].dt.year
66
tips["date2_month"] = tips["date2"].dt.month
77
tips["date1_next"] = tips["date1"] + pd.offsets.MonthBegin()
8-
tips["months_between"] = tips["date2"].dt.to_period("M") - tips[
9-
"date1"
10-
].dt.to_period("M")
8+
tips["months_between"] = tips["date2"].dt.to_period("M") - tips["date1"].dt.to_period(
9+
"M"
10+
)
1111
12-
tips[
13-
["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"]
14-
]
12+
tips[["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"]]
1513
1614
.. ipython:: python
1715
:suppress:

doc/source/getting_started/install.rst

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ obtain these directories with.
108108
.. code-block:: python
109109
110110
import sys
111+
111112
sys.path
112113
113114
One way you could be encountering this error is if you have multiple Python installations on your system

doc/source/getting_started/intro_tutorials/07_reshape_table_layout.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ I want to sort the Titanic data according to the cabin class and age in descendi
115115

116116
.. ipython:: python
117117
118-
titanic.sort_values(by=['Pclass', 'Age'], ascending=False).head()
118+
titanic.sort_values(by=["Pclass", "Age"], ascending=False).head()
119119
120120
With :meth:`DataFrame.sort_values`, the rows in the table are sorted according to the
121121
defined column(s). The index will follow the row order.

doc/source/getting_started/intro_tutorials/08_combine_dataframes.rst

+10-13
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ Westminster* in respectively Paris, Antwerp and London.
4040

4141
.. ipython:: python
4242
43-
air_quality_no2 = pd.read_csv("data/air_quality_no2_long.csv",
44-
parse_dates=True)
45-
air_quality_no2 = air_quality_no2[["date.utc", "location",
46-
"parameter", "value"]]
43+
air_quality_no2 = pd.read_csv("data/air_quality_no2_long.csv", parse_dates=True)
44+
air_quality_no2 = air_quality_no2[["date.utc", "location", "parameter", "value"]]
4745
air_quality_no2.head()
4846
4947
.. raw:: html
@@ -75,10 +73,8 @@ Westminster* in respectively Paris, Antwerp and London.
7573

7674
.. ipython:: python
7775
78-
air_quality_pm25 = pd.read_csv("data/air_quality_pm25_long.csv",
79-
parse_dates=True)
80-
air_quality_pm25 = air_quality_pm25[["date.utc", "location",
81-
"parameter", "value"]]
76+
air_quality_pm25 = pd.read_csv("data/air_quality_pm25_long.csv", parse_dates=True)
77+
air_quality_pm25 = air_quality_pm25[["date.utc", "location", "parameter", "value"]]
8278
air_quality_pm25.head()
8379
8480
.. raw:: html
@@ -123,9 +119,9 @@ concatenated tables to verify the operation:
123119

124120
.. ipython:: python
125121
126-
print('Shape of the ``air_quality_pm25`` table: ', air_quality_pm25.shape)
127-
print('Shape of the ``air_quality_no2`` table: ', air_quality_no2.shape)
128-
print('Shape of the resulting ``air_quality`` table: ', air_quality.shape)
122+
print("Shape of the ``air_quality_pm25`` table: ", air_quality_pm25.shape)
123+
print("Shape of the ``air_quality_no2`` table: ", air_quality_no2.shape)
124+
print("Shape of the resulting ``air_quality`` table: ", air_quality.shape)
129125
130126
Hence, the resulting table has 3178 = 1110 + 2068 rows.
131127

@@ -265,8 +261,9 @@ Add the parameters' full description and name, provided by the parameters metada
265261
266262
.. ipython:: python
267263
268-
air_quality = pd.merge(air_quality, air_quality_parameters,
269-
how='left', left_on='parameter', right_on='id')
264+
air_quality = pd.merge(
265+
air_quality, air_quality_parameters, how="left", left_on="parameter", right_on="id"
266+
)
270267
air_quality.head()
271268
272269
Compared to the previous example, there is no common column name.

doc/source/getting_started/intro_tutorials/09_timeseries.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ What is the average :math:`NO_2` concentration for each day of the week for each
174174

175175
.. ipython:: python
176176
177-
air_quality.groupby(
178-
[air_quality["datetime"].dt.weekday, "location"])["value"].mean()
177+
air_quality.groupby([air_quality["datetime"].dt.weekday, "location"])["value"].mean()
179178
180179
Remember the split-apply-combine pattern provided by ``groupby`` from the
181180
:ref:`tutorial on statistics calculation <10min_tut_06_stats>`?

doc/source/user_guide/10min.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ Stack
550550
.. ipython:: python
551551
552552
arrays = [
553-
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
554-
["one", "two", "one", "two", "one", "two", "one", "two"],
553+
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
554+
["one", "two", "one", "two", "one", "two", "one", "two"],
555555
]
556556
index = pd.MultiIndex.from_arrays(arrays, names=["first", "second"])
557557
df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=["A", "B"])

0 commit comments

Comments
 (0)