Skip to content

DOC: updates documentations Closes #21749 #42979

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 5 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
11 changes: 5 additions & 6 deletions pandas/_testing/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,18 @@ def network(
Tests decorated with @network will fail if it's possible to make a network
connection to another URL (defaults to google.com)::

>>> from pandas._testing import network
>>> from pandas.io.common import urlopen
>>> @network
>>> from pandas import _testing as ts
>>> @ts.network
... def test_network():
... with urlopen("rabbit://bonanza.com"):
... with pd.io.common.urlopen("rabbit://bonanza.com"):
... pass
Traceback
...
URLError: <urlopen error unknown url type: rabit>

You can specify alternative URLs::

>>> @network("https://www.yahoo.com")
>>> @ts.network("https://www.yahoo.com")
... def test_something_with_yahoo():
... raise IOError("Failure Message")
>>> test_something_with_yahoo()
Expand All @@ -183,7 +182,7 @@ def network(
If you set check_before_test, it will check the url first and not run the
test on failure::

>>> @network("failing://url.blaher", check_before_test=True)
>>> @ts.network("failing://url.blaher", check_before_test=True)
... def test_something():
... print("I ran!")
... raise ValueError("Failure")
Expand Down
20 changes: 10 additions & 10 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ def assert_index_equal(

Examples
--------
>>> from pandas.testing import assert_index_equal
>>> from pandas import testing as tm
>>> a = pd.Index([1, 2, 3])
>>> b = pd.Index([1, 2, 3])
>>> assert_index_equal(a, b)
>>> tm.assert_index_equal(a, b)
"""
__tracebackhide__ = True

Expand Down Expand Up @@ -794,10 +794,10 @@ def assert_extension_array_equal(

Examples
--------
>>> from pandas.testing import assert_extension_array_equal
>>> from pandas import testing as tm
>>> a = pd.Series([1, 2, 3, 4])
>>> b, c = a.array, a.array
>>> assert_extension_array_equal(b, c)
>>> tm.assert_extension_array_equal(b, c)
"""
if check_less_precise is not no_default:
warnings.warn(
Expand Down Expand Up @@ -938,10 +938,10 @@ def assert_series_equal(

Examples
--------
>>> from pandas.testing import assert_series_equal
>>> from pandas import testing as tm
>>> a = pd.Series([1, 2, 3, 4])
>>> b = pd.Series([1, 2, 3, 4])
>>> assert_series_equal(a, b)
>>> tm.assert_series_equal(a, b)
"""
__tracebackhide__ = True

Expand Down Expand Up @@ -1203,17 +1203,17 @@ def assert_frame_equal(
This example shows comparing two DataFrames that are equal
but with columns of differing dtypes.

>>> from pandas._testing import assert_frame_equal
>>> from pandas import _testing as ts
>>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})

df1 equals itself.

>>> assert_frame_equal(df1, df1)
>>> ts.assert_frame_equal(df1, df1)

df1 differs from df2 as column 'b' is of a different type.

>>> assert_frame_equal(df1, df2)
>>> ts.assert_frame_equal(df1, df2)
Traceback (most recent call last):
...
AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different
Expand All @@ -1224,7 +1224,7 @@ def assert_frame_equal(

Ignore differing dtypes in columns with check_dtype.

>>> assert_frame_equal(df1, df2, check_dtype=False)
>>> ts.assert_frame_equal(df1, df2, check_dtype=False)
"""
__tracebackhide__ = True

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ def take(

Examples
--------
>>> from pandas.api.extensions import take
>>> from pandas.pai.extensions import take

With the default ``allow_fill=False``, negative numbers indicate
positional indices from the right.
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ def register_extension_dtype(cls: type_t[ExtensionDtypeT]) -> type_t[ExtensionDt

Examples
--------
>>> from pandas.api.extensions import register_extension_dtype
>>> from pandas.api.extensions import ExtensionDtype
>>> from pandas.api.extensions import register_extension_dtype, ExtensionDtype
>>> @register_extension_dtype
... class MyExtensionDtype(ExtensionDtype):
... name = "myextension"
Expand Down
9 changes: 3 additions & 6 deletions pandas/io/formats/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,8 @@ def _select_iterator(self, over: str) -> type[RowStringIterator]:
class LongTableBuilder(GenericTableBuilder):
"""Concrete table builder for longtable.

>>> from pandas import DataFrame
>>> from pandas.io.formats import format as fmt
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> formatter = fmt.DataFrameFormatter(df)
>>> builder = LongTableBuilder(formatter, caption='a long table',
... label='tab:long', column_format='lrl')
Expand Down Expand Up @@ -578,9 +577,8 @@ def env_end(self) -> str:
class RegularTableBuilder(GenericTableBuilder):
"""Concrete table builder for regular table.

>>> from pandas import DataFrame
>>> from pandas.io.formats import format as fmt
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> formatter = fmt.DataFrameFormatter(df)
>>> builder = RegularTableBuilder(formatter, caption='caption', label='lab',
... column_format='lrc')
Expand Down Expand Up @@ -625,9 +623,8 @@ def env_end(self) -> str:
class TabularBuilder(GenericTableBuilder):
"""Concrete table builder for tabular environment.

>>> from pandas import DataFrame
>>> from pandas.io.formats import format as fmt
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
>>> formatter = fmt.DataFrameFormatter(df)
>>> builder = TabularBuilder(formatter, column_format='lrc')
>>> table = builder.get_result()
Expand Down
6 changes: 4 additions & 2 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3080,7 +3080,8 @@ class StataWriter117(StataWriter):

Directly write a zip file
>>> compression = {"method": "zip", "archive_name": "data_file.dta"}
>>> writer = StataWriter117('./data_file.zip', data, compression=compression)
>>> writer = StataWriter117('./data_file.zip',
... data, compression=compression)
>>> writer.write_file()

Or with long strings stored in strl format
Expand Down Expand Up @@ -3472,7 +3473,8 @@ class StataWriterUTF8(StataWriter117):

Directly write a zip file
>>> compression = {"method": "zip", "archive_name": "data_file.dta"}
>>> writer = StataWriterUTF8('./data_file.zip', data, compression=compression)
>>> writer = StataWriterUTF8('./data_file.zip',
... data, compression=compression)
>>> writer.write_file()

Or with long strings stored in strl format
Expand Down
3 changes: 2 additions & 1 deletion pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class from pandas.tseries.offsets
Holiday: July 3rd (month=7, day=3, )

>>> NewYears = Holiday(
... "New Years Day", month=1, day=1, observance=nearest_workday
... "New Years Day", month=1, day=1,
... observance=nearest_workday
... )
>>> NewYears # doctest: +SKIP
Holiday: New Years Day (
Expand Down