Skip to content

DOC: Fix code block line length #36773

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 23 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0f76a2a
DOC: Fix code block line length
dsaxton Oct 1, 2020
94ba010
Fix
dsaxton Oct 1, 2020
5b5268e
Fix
dsaxton Oct 1, 2020
f089659
Another
dsaxton Oct 1, 2020
1b9f83b
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
f57fa6c
Fix
dsaxton Oct 2, 2020
a4fddc9
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
31032a5
Fix
dsaxton Oct 2, 2020
43cac82
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
cb6b0a0
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
1b6f347
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
3e10b2c
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 2, 2020
ce985ba
Fix
dsaxton Oct 2, 2020
d791bd5
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 3, 2020
ec204d2
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 3, 2020
33a2e26
Fix
dsaxton Oct 3, 2020
aad9468
Fix
dsaxton Oct 3, 2020
00afb92
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 4, 2020
918b870
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 4, 2020
6f8d68d
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 5, 2020
b9ae2ac
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 5, 2020
90126cc
Merge remote-tracking branch 'upstream/master' into fix-doc-line-length
dsaxton Oct 5, 2020
def814f
Fix
dsaxton Oct 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions doc/source/user_guide/categorical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ The ordering of the categorical is determined by the ``categories`` of that colu

dfs = pd.DataFrame(
{
"A": pd.Categorical(list("bbeebbaa"), categories=["e", "a", "b"], ordered=True),
"A": pd.Categorical(
list("bbeebbaa"),
categories=["e", "a", "b"],
ordered=True,
),
"B": [1, 2, 1, 2, 2, 1, 2, 1],
}
)
Expand Down Expand Up @@ -642,7 +646,13 @@ Groupby will also show "unused" categories:
df.groupby("cats").mean()

cats2 = pd.Categorical(["a", "a", "b", "b"], categories=["a", "b", "c"])
df2 = pd.DataFrame({"cats": cats2, "B": ["c", "d", "c", "d"], "values": [1, 2, 3, 4]})
df2 = pd.DataFrame(
{
"cats": cats2,
"B": ["c", "d", "c", "d"],
"values": [1, 2, 3, 4],
}
)
df2.groupby(["cats", "B"]).mean()


Expand Down Expand Up @@ -1115,7 +1125,11 @@ You can use ``fillna`` to handle missing values before applying a function.
.. ipython:: python

df = pd.DataFrame(
{"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"], "cats": pd.Categorical([1, 2, 3, 2])}
{
"a": [1, 2, 3, 4],
"b": ["a", "b", "c", "d"],
"cats": pd.Categorical([1, 2, 3, 2]),
}
)
df.apply(lambda row: type(row["cats"]), axis=1)
df.apply(lambda col: col.dtype, axis=0)
Expand Down
68 changes: 57 additions & 11 deletions doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,12 @@ Note that ``infer_datetime_format`` is sensitive to ``dayfirst``. With
.. ipython:: python

# Try to infer the format for the index column
df = pd.read_csv("foo.csv", index_col=0, parse_dates=True, infer_datetime_format=True)
df = pd.read_csv(
"foo.csv",
index_col=0,
parse_dates=True,
infer_datetime_format=True,
)
df

.. ipython:: python
Expand Down Expand Up @@ -1046,9 +1051,19 @@ writing to a file). For example:

val = "0.3066101993807095471566981359501369297504425048828125"
data = "a,b,c\n1,2,{0}".format(val)
abs(pd.read_csv(StringIO(data), engine="c", float_precision=None)["c"][0] - float(val))
abs(
pd.read_csv(StringIO(data), engine="c", float_precision="high")["c"][0] - float(val)
pd.read_csv(
StringIO(data),
engine="c",
float_precision=None,
)["c"][0] - float(val)
)
abs(
pd.read_csv(
StringIO(data),
engine="c",
float_precision="high",
)["c"][0] - float(val)
)
abs(
pd.read_csv(StringIO(data), engine="c", float_precision="round_trip")["c"][0]
Expand Down Expand Up @@ -2517,7 +2532,12 @@ columns to strings.
.. code-block:: python

url_mcc = "https://en.wikipedia.org/wiki/Mobile_country_code"
dfs = pd.read_html(url_mcc, match="Telekom Albania", header=0, converters={"MNC": str})
dfs = pd.read_html(
url_mcc,
match="Telekom Albania",
header=0,
converters={"MNC": str},
)

Use some combination of the above:

Expand Down Expand Up @@ -3570,7 +3590,12 @@ HDFStore will by default not drop rows that are all missing. This behavior can b

.. ipython:: python

df_with_missing = pd.DataFrame({"col1": [0, np.nan, 2], "col2": [1, np.nan, np.nan]})
df_with_missing = pd.DataFrame(
{
"col1": [0, np.nan, 2],
"col2": [1, np.nan, np.nan],
}
)
df_with_missing

df_with_missing.to_hdf("file.h5", "df_with_missing", format="table", mode="w")
Expand Down Expand Up @@ -3944,7 +3969,8 @@ specified in the format: ``<float>(<unit>)``, where float may be signed (and fra
{
"A": pd.Timestamp("20130101"),
"B": [
pd.Timestamp("20130101") + timedelta(days=i, seconds=10) for i in range(10)
pd.Timestamp("20130101") + timedelta(days=i, seconds=10)
for i in range(10)
],
}
)
Expand Down Expand Up @@ -4241,7 +4267,11 @@ results.
store.select("df2_mt")

# as a multiple
store.select_as_multiple(["df1_mt", "df2_mt"], where=["A>0", "B>0"], selector="df1_mt")
store.select_as_multiple(
["df1_mt", "df2_mt"],
where=["A>0", "B>0"],
selector="df1_mt",
)


Delete from a table
Expand Down Expand Up @@ -4797,8 +4827,16 @@ Read only certain columns of a parquet file.

.. ipython:: python

result = pd.read_parquet("example_fp.parquet", engine="fastparquet", columns=["a", "b"])
result = pd.read_parquet("example_pa.parquet", engine="pyarrow", columns=["a", "b"])
result = pd.read_parquet(
"example_fp.parquet",
engine="fastparquet",
columns=["a", "b"],
)
result = pd.read_parquet(
"example_pa.parquet",
engine="pyarrow",
columns=["a", "b"],
)
result.dtypes


Expand Down Expand Up @@ -5176,7 +5214,11 @@ to pass to :func:`pandas.to_datetime`:
.. code-block:: python

pd.read_sql_table("data", engine, parse_dates={"Date": "%Y-%m-%d"})
pd.read_sql_table("data", engine, parse_dates={"Date": {"format": "%Y-%m-%d %H:%M:%S"}})
pd.read_sql_table(
"data",
engine,
parse_dates={"Date": {"format": "%Y-%m-%d %H:%M:%S"}},
)


You can check if a table exists using :func:`~pandas.io.sql.has_table`
Expand Down Expand Up @@ -5593,7 +5635,11 @@ avoid converting categorical columns into ``pd.Categorical``:

.. code-block:: python

df = pd.read_spss("spss_data.sav", usecols=["foo", "bar"], convert_categoricals=False)
df = pd.read_spss(
"spss_data.sav",
usecols=["foo", "bar"],
convert_categoricals=False,
)

More information about the SAV and ZSAV file formats is available here_.

Expand Down
38 changes: 33 additions & 5 deletions doc/source/user_guide/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,13 @@ calling ``sort_index``, of course). Here is a more complex example:
.. ipython:: python

columns = pd.MultiIndex.from_tuples(
[("A", "cat"), ("B", "dog"), ("B", "cat"), ("A", "dog")], names=["exp", "animal"]
[
("A", "cat"),
("B", "dog"),
("B", "cat"),
("A", "dog"),
],
names=["exp", "animal"],
)
index = pd.MultiIndex.from_product(
[("bar", "baz", "foo", "qux"), ("one", "two")], names=["first", "second"]
Expand Down Expand Up @@ -800,14 +806,26 @@ parameter.

.. ipython:: python

df.pivot_table(values="val0", index="row", columns="col", aggfunc="mean", fill_value=0)
df.pivot_table(
values="val0",
index="row",
columns="col",
aggfunc="mean",
fill_value=0,
)

Also note that we can pass in other aggregation functions as well. For example,
we can also pass in ``sum``.

.. ipython:: python

df.pivot_table(values="val0", index="row", columns="col", aggfunc="sum", fill_value=0)
df.pivot_table(
values="val0",
index="row",
columns="col",
aggfunc="sum",
fill_value=0,
)

Another aggregation we can do is calculate the frequency in which the columns
and rows occur together a.k.a. "cross tabulation". To do this, we can pass
Expand All @@ -825,7 +843,12 @@ We can also perform multiple aggregations. For example, to perform both a

.. ipython:: python

df.pivot_table(values="val0", index="row", columns="col", aggfunc=["mean", "sum"])
df.pivot_table(
values="val0",
index="row",
columns="col",
aggfunc=["mean", "sum"],
)

Note to aggregate over multiple value columns, we can pass in a list to the
``values`` parameter.
Expand All @@ -839,7 +862,12 @@ Note to subdivide over multiple columns we can pass in a list to the

.. ipython:: python

df.pivot_table(values=["val0"], index="row", columns=["item", "col"], aggfunc=["mean"])
df.pivot_table(
values=["val0"],
index="row",
columns=["item", "col"],
aggfunc=["mean"],
)

.. _reshaping.explode:

Expand Down
23 changes: 18 additions & 5 deletions doc/source/user_guide/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ i.e., from the end of the string to the beginning of the string:
.. ipython:: python

s3 = pd.Series(
["A", "B", "C", "Aaba", "Baca", "", np.nan, "CABA", "dog", "cat"], dtype="string"
["A", "B", "C", "Aaba", "Baca", "", np.nan, "CABA", "dog", "cat"],
dtype="string",
)
s3
s3.str.replace("^.a|dog", "XX-XX ", case=False)
Expand Down Expand Up @@ -515,7 +516,10 @@ DataFrame with one column per group.

.. ipython:: python

pd.Series(["a1", "b2", "c3"], dtype="string").str.extract(r"([ab])(\d)", expand=False)
pd.Series(
["a1", "b2", "c3"],
dtype="string",
).str.extract(r"([ab])(\d)", expand=False)

Elements that do not match return a row filled with ``NaN``. Thus, a
Series of messy strings can be "converted" into a like-indexed Series
Expand All @@ -536,7 +540,10 @@ and optional groups like

.. ipython:: python

pd.Series(["a1", "b2", "3"], dtype="string").str.extract(r"([ab])?(\d)", expand=False)
pd.Series(
["a1", "b2", "3"],
dtype="string",
).str.extract(r"([ab])?(\d)", expand=False)

can also be used. Note that any capture group names in the regular
expression will be used for column names; otherwise capture group
Expand Down Expand Up @@ -661,13 +668,19 @@ Or whether elements match a pattern:

.. ipython:: python

pd.Series(["1", "2", "3a", "3b", "03c", "4dx"], dtype="string").str.match(pattern)
pd.Series(
["1", "2", "3a", "3b", "03c", "4dx"],
dtype="string",
).str.match(pattern)

.. versionadded:: 1.1.0

.. ipython:: python

pd.Series(["1", "2", "3a", "3b", "03c", "4dx"], dtype="string").str.fullmatch(pattern)
pd.Series(
["1", "2", "3a", "3b", "03c", "4dx"],
dtype="string",
).str.fullmatch(pattern)

.. note::

Expand Down
5 changes: 4 additions & 1 deletion doc/source/user_guide/timedeltas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ Similarly to other of the datetime-like indices, ``DatetimeIndex`` and ``PeriodI

.. ipython:: python

s = pd.Series(np.arange(100), index=pd.timedelta_range("1 days", periods=100, freq="h"))
s = pd.Series(
np.arange(100),
index=pd.timedelta_range("1 days", periods=100, freq="h"),
)
s

Selections work similarly, with coercion on string-likes and slices:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exclude =
env # exclude asv benchmark environments from linting

[flake8-rst]
max-line-length = 88
max-line-length = 84
bootstrap =
import numpy as np
import pandas as pd
Expand Down