Skip to content

Commit b7a8bfd

Browse files
Dushimirimana SalomonDushimirimana Salomon
Dushimirimana Salomon
authored and
Dushimirimana Salomon
committed
DOC: updates documentations Closes pandas-dev#21749
1 parent 126a19d commit b7a8bfd

File tree

12 files changed

+69
-71
lines changed

12 files changed

+69
-71
lines changed

pandas/_testing/_io.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,18 @@ def network(
160160
Tests decorated with @network will fail if it's possible to make a network
161161
connection to another URL (defaults to google.com)::
162162
163-
>>> from pandas._testing import network
164-
>>> from pandas.io.common import urlopen
165-
>>> @network
163+
>>> import pandas as pd
164+
>>> @pd._testing.network
166165
... def test_network():
167-
... with urlopen("rabbit://bonanza.com"):
166+
... with pd.io.common.urlopen("rabbit://bonanza.com"):
168167
... pass
169168
Traceback
170169
...
171170
URLError: <urlopen error unknown url type: rabit>
172171
173172
You can specify alternative URLs::
174173
175-
>>> @network("https://www.yahoo.com")
174+
>>> @pd._testing.network("https://www.yahoo.com")
176175
... def test_something_with_yahoo():
177176
... raise IOError("Failure Message")
178177
>>> test_something_with_yahoo()
@@ -183,7 +182,7 @@ def network(
183182
If you set check_before_test, it will check the url first and not run the
184183
test on failure::
185184
186-
>>> @network("failing://url.blaher", check_before_test=True)
185+
>>> @pd._testing.network("failing://url.blaher", check_before_test=True)
187186
... def test_something():
188187
... print("I ran!")
189188
... raise ValueError("Failure")

pandas/_testing/asserters.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ def assert_index_equal(
303303
304304
Examples
305305
--------
306-
>>> from pandas.testing import assert_index_equal
306+
>>> import pandas as pd
307307
>>> a = pd.Index([1, 2, 3])
308308
>>> b = pd.Index([1, 2, 3])
309-
>>> assert_index_equal(a, b)
309+
>>> pd.testing.assert_index_equal(a, b)
310310
"""
311311
__tracebackhide__ = True
312312

@@ -794,10 +794,10 @@ def assert_extension_array_equal(
794794
795795
Examples
796796
--------
797-
>>> from pandas.testing import assert_extension_array_equal
797+
>>> import pandas as pd
798798
>>> a = pd.Series([1, 2, 3, 4])
799799
>>> b, c = a.array, a.array
800-
>>> assert_extension_array_equal(b, c)
800+
>>> pd.testing.assert_extension_array_equal(b, c)
801801
"""
802802
if check_less_precise is not no_default:
803803
warnings.warn(
@@ -938,10 +938,10 @@ def assert_series_equal(
938938
939939
Examples
940940
--------
941-
>>> from pandas.testing import assert_series_equal
941+
>>> import pandas as pd
942942
>>> a = pd.Series([1, 2, 3, 4])
943943
>>> b = pd.Series([1, 2, 3, 4])
944-
>>> assert_series_equal(a, b)
944+
>>> pd.testing.assert_series_equal(a, b)
945945
"""
946946
__tracebackhide__ = True
947947

@@ -1203,17 +1203,17 @@ def assert_frame_equal(
12031203
This example shows comparing two DataFrames that are equal
12041204
but with columns of differing dtypes.
12051205
1206-
>>> from pandas._testing import assert_frame_equal
1206+
>>> import pandas as pd
12071207
>>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
12081208
>>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})
12091209
12101210
df1 equals itself.
12111211
1212-
>>> assert_frame_equal(df1, df1)
1212+
>>> pd._testing.assert_frame_equal(df1, df1)
12131213
12141214
df1 differs from df2 as column 'b' is of a different type.
12151215
1216-
>>> assert_frame_equal(df1, df2)
1216+
>>> pd._testing.assert_frame_equal(df1, df2)
12171217
Traceback (most recent call last):
12181218
...
12191219
AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different
@@ -1224,7 +1224,7 @@ def assert_frame_equal(
12241224
12251225
Ignore differing dtypes in columns with check_dtype.
12261226
1227-
>>> assert_frame_equal(df1, df2, check_dtype=False)
1227+
>>> pd._testing.assert_frame_equal(df1, df2, check_dtype=False)
12281228
"""
12291229
__tracebackhide__ = True
12301230

pandas/core/algorithms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1462,20 +1462,20 @@ def take(
14621462
14631463
Examples
14641464
--------
1465-
>>> from pandas.api.extensions import take
1465+
>>> import pandas as pd
14661466
14671467
With the default ``allow_fill=False``, negative numbers indicate
14681468
positional indices from the right.
14691469
1470-
>>> take(np.array([10, 20, 30]), [0, 0, -1])
1470+
>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1])
14711471
array([10, 10, 30])
14721472
14731473
Setting ``allow_fill=True`` will place `fill_value` in those positions.
14741474
1475-
>>> take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True)
1475+
>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True)
14761476
array([10., 10., nan])
14771477
1478-
>>> take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True,
1478+
>>> pd.api.extensions.take(np.array([10, 20, 30]), [0, 0, -1], allow_fill=True,
14791479
... fill_value=-10)
14801480
array([ 10, 10, -10])
14811481
"""

pandas/core/arrays/sparse/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ class SparseArray(OpsMixin, PandasObject, ExtensionArray):
282282
283283
Examples
284284
--------
285-
>>> from pandas.arrays import SparseArray
286-
>>> arr = SparseArray([0, 0, 1, 2])
285+
>>> import pandas as pd
286+
>>> arr = pd.arrays.SparseArray([0, 0, 1, 2])
287287
>>> arr
288288
[0, 0, 1, 2]
289289
Fill: 0

pandas/core/dtypes/base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,9 @@ def register_extension_dtype(cls: type_t[ExtensionDtypeT]) -> type_t[ExtensionDt
387387
388388
Examples
389389
--------
390-
>>> from pandas.api.extensions import register_extension_dtype
391-
>>> from pandas.api.extensions import ExtensionDtype
392-
>>> @register_extension_dtype
393-
... class MyExtensionDtype(ExtensionDtype):
390+
>>> import pandas as pd
391+
>>> @pd.api.extensions.register_extension_dtype
392+
... class MyExtensionDtype(pd.api.extensions.ExtensionDtype):
394393
... name = "myextension"
395394
"""
396395
_registry.register(cls)

pandas/core/dtypes/common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1450,15 +1450,15 @@ def is_extension_array_dtype(arr_or_dtype) -> bool:
14501450
14511451
Examples
14521452
--------
1453-
>>> from pandas.api.types import is_extension_array_dtype
1453+
>>> import pandas as pd
14541454
>>> arr = pd.Categorical(['a', 'b'])
1455-
>>> is_extension_array_dtype(arr)
1455+
>>> pd.api.types.is_extension_array_dtype(arr)
14561456
True
1457-
>>> is_extension_array_dtype(arr.dtype)
1457+
>>> pd.api.types.is_extension_array_dtype(arr.dtype)
14581458
True
14591459
14601460
>>> arr = np.array(['a', 'b'])
1461-
>>> is_extension_array_dtype(arr.dtype)
1461+
>>> pd.api.types.is_extension_array_dtype(arr.dtype)
14621462
False
14631463
"""
14641464
dtype = getattr(arr_or_dtype, "dtype", arr_or_dtype)

pandas/core/dtypes/concat.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -191,42 +191,42 @@ def union_categoricals(
191191
192192
Examples
193193
--------
194-
>>> from pandas.api.types import union_categoricals
194+
>>> import pandas as pd
195195
196196
If you want to combine categoricals that do not necessarily have
197-
the same categories, `union_categoricals` will combine a list-like
197+
the same categories, `pd.api.types.union_categoricals` will combine a list-like
198198
of categoricals. The new categories will be the union of the
199199
categories being combined.
200200
201201
>>> a = pd.Categorical(["b", "c"])
202202
>>> b = pd.Categorical(["a", "b"])
203-
>>> union_categoricals([a, b])
203+
>>> pd.api.types.union_categoricals([a, b])
204204
['b', 'c', 'a', 'b']
205205
Categories (3, object): ['b', 'c', 'a']
206206
207207
By default, the resulting categories will be ordered as they appear
208208
in the `categories` of the data. If you want the categories to be
209209
lexsorted, use `sort_categories=True` argument.
210210
211-
>>> union_categoricals([a, b], sort_categories=True)
211+
>>> pd.api.types.union_categoricals([a, b], sort_categories=True)
212212
['b', 'c', 'a', 'b']
213213
Categories (3, object): ['a', 'b', 'c']
214214
215-
`union_categoricals` also works with the case of combining two
215+
`pd.api.types.union_categoricals` also works with the case of combining two
216216
categoricals of the same categories and order information (e.g. what
217217
you could also `append` for).
218218
219219
>>> a = pd.Categorical(["a", "b"], ordered=True)
220220
>>> b = pd.Categorical(["a", "b", "a"], ordered=True)
221-
>>> union_categoricals([a, b])
221+
>>> pd.api.types.union_categoricals([a, b])
222222
['a', 'b', 'a', 'b', 'a']
223223
Categories (2, object): ['a' < 'b']
224224
225225
Raises `TypeError` because the categories are ordered and not identical.
226226
227227
>>> a = pd.Categorical(["a", "b"], ordered=True)
228228
>>> b = pd.Categorical(["a", "b", "c"], ordered=True)
229-
>>> union_categoricals([a, b])
229+
>>> pd.api.types.union_categoricals([a, b])
230230
Traceback (most recent call last):
231231
...
232232
TypeError: to union ordered Categoricals, all categories must be the same
@@ -238,17 +238,17 @@ def union_categoricals(
238238
239239
>>> a = pd.Categorical(["a", "b", "c"], ordered=True)
240240
>>> b = pd.Categorical(["c", "b", "a"], ordered=True)
241-
>>> union_categoricals([a, b], ignore_order=True)
241+
>>> pd.api.types.union_categoricals([a, b], ignore_order=True)
242242
['a', 'b', 'c', 'c', 'b', 'a']
243243
Categories (3, object): ['a', 'b', 'c']
244244
245-
`union_categoricals` also works with a `CategoricalIndex`, or `Series`
245+
`pd.api.types.union_categoricals` also works with a `CategoricalIndex`, or `Series`
246246
containing categorical data, but note that the resulting array will
247247
always be a plain `Categorical`
248248
249249
>>> a = pd.Series(["b", "c"], dtype='category')
250250
>>> b = pd.Series(["a", "b"], dtype='category')
251-
>>> union_categoricals([a, b])
251+
>>> pd.api.types.union_categoricals([a, b])
252252
['b', 'c', 'a', 'b']
253253
Categories (3, object): ['b', 'c', 'a']
254254
"""

pandas/core/dtypes/inference.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ def is_number(obj) -> bool:
5151
5252
Examples
5353
--------
54-
>>> from pandas.api.types import is_number
55-
>>> is_number(1)
54+
>>> import pandas as pd
55+
>>> pd.api.types.is_number(1)
5656
True
57-
>>> is_number(7.15)
57+
>>> pd.api.types.is_number(7.15)
5858
True
5959
6060
Booleans are valid because they are int subclass.
6161
62-
>>> is_number(False)
62+
>>> pd.api.types.is_number(False)
6363
True
6464
65-
>>> is_number("foo")
65+
>>> pd.api.types.is_number("foo")
6666
False
67-
>>> is_number("5")
67+
>>> pd.api.types.is_number("5")
6868
False
6969
"""
7070
return isinstance(obj, (Number, np.number))

pandas/core/generic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5681,8 +5681,8 @@ def astype(
56815681
56825682
Convert to ordered categorical type with custom ordering:
56835683
5684-
>>> from pandas.api.types import CategoricalDtype
5685-
>>> cat_dtype = CategoricalDtype(
5684+
>>> import pandas as pd
5685+
>>> cat_dtype = pd.api.types.CategoricalDtype(
56865686
... categories=[2, 1], ordered=True)
56875687
>>> ser.astype(cat_dtype)
56885688
0 1
@@ -8042,10 +8042,10 @@ def resample(
80428042
80438043
To replace the use of the deprecated `loffset` argument:
80448044
8045-
>>> from pandas.tseries.frequencies import to_offset
8045+
>>> import pandas as pd
80468046
>>> loffset = '19min'
80478047
>>> ts_out = ts.resample('17min').sum()
8048-
>>> ts_out.index = ts_out.index + to_offset(loffset)
8048+
>>> ts_out.index = ts_out.index + pd.tseries.frequencies.to_offset(loffset)
80498049
>>> ts_out
80508050
2000-10-01 23:33:00 0
80518051
2000-10-01 23:50:00 9

pandas/io/formats/latex.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ def _select_iterator(self, over: str) -> type[RowStringIterator]:
488488
class LongTableBuilder(GenericTableBuilder):
489489
"""Concrete table builder for longtable.
490490
491-
>>> from pandas import DataFrame
491+
>>> import pandas as pd
492492
>>> from pandas.io.formats import format as fmt
493-
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
493+
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
494494
>>> formatter = fmt.DataFrameFormatter(df)
495495
>>> builder = LongTableBuilder(formatter, caption='a long table',
496496
... label='tab:long', column_format='lrl')
@@ -578,9 +578,9 @@ def env_end(self) -> str:
578578
class RegularTableBuilder(GenericTableBuilder):
579579
"""Concrete table builder for regular table.
580580
581-
>>> from pandas import DataFrame
581+
>>> import pandas as pd
582582
>>> from pandas.io.formats import format as fmt
583-
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
583+
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
584584
>>> formatter = fmt.DataFrameFormatter(df)
585585
>>> builder = RegularTableBuilder(formatter, caption='caption', label='lab',
586586
... column_format='lrc')
@@ -625,9 +625,9 @@ def env_end(self) -> str:
625625
class TabularBuilder(GenericTableBuilder):
626626
"""Concrete table builder for tabular environment.
627627
628-
>>> from pandas import DataFrame
628+
>>> import pandas as pd
629629
>>> from pandas.io.formats import format as fmt
630-
>>> df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
630+
>>> df = pd.DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
631631
>>> formatter = fmt.DataFrameFormatter(df)
632632
>>> builder = TabularBuilder(formatter, column_format='lrc')
633633
>>> table = builder.get_result()

pandas/io/stata.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3073,20 +3073,20 @@ class StataWriter117(StataWriter):
30733073
30743074
Examples
30753075
--------
3076-
>>> from pandas.io.stata import StataWriter117
3076+
>>> import pandas as pd
30773077
>>> data = pd.DataFrame([[1.0, 1, 'a']], columns=['a', 'b', 'c'])
3078-
>>> writer = StataWriter117('./data_file.dta', data)
3078+
>>> writer = pd.io.stata.StataWriter117('./data_file.dta', data)
30793079
>>> writer.write_file()
30803080
30813081
Directly write a zip file
30823082
>>> compression = {"method": "zip", "archive_name": "data_file.dta"}
3083-
>>> writer = StataWriter117('./data_file.zip', data, compression=compression)
3083+
>>> writer = pd.io.stata.StataWriter117('./data_file.zip', data, compression=compression)
30843084
>>> writer.write_file()
30853085
30863086
Or with long strings stored in strl format
30873087
>>> data = pd.DataFrame([['A relatively long string'], [''], ['']],
30883088
... columns=['strls'])
3089-
>>> writer = StataWriter117('./data_file_with_long_strings.dta', data,
3089+
>>> writer = pd.io.stata.StataWriter117('./data_file_with_long_strings.dta', data,
30903090
... convert_strl=['strls'])
30913091
>>> writer.write_file()
30923092
"""
@@ -3465,21 +3465,21 @@ class StataWriterUTF8(StataWriter117):
34653465
--------
34663466
Using Unicode data and column names
34673467
3468-
>>> from pandas.io.stata import StataWriterUTF8
3468+
>>> import pandas as pd
34693469
>>> data = pd.DataFrame([[1.0, 1, 'ᴬ']], columns=['a', 'β', 'ĉ'])
3470-
>>> writer = StataWriterUTF8('./data_file.dta', data)
3470+
>>> writer = pd.io.stata.StataWriterUTF8('./data_file.dta', data)
34713471
>>> writer.write_file()
34723472
34733473
Directly write a zip file
34743474
>>> compression = {"method": "zip", "archive_name": "data_file.dta"}
3475-
>>> writer = StataWriterUTF8('./data_file.zip', data, compression=compression)
3475+
>>> writer = pd.io.stata.StataWriterUTF8('./data_file.zip', data, compression=compression)
34763476
>>> writer.write_file()
34773477
34783478
Or with long strings stored in strl format
34793479
34803480
>>> data = pd.DataFrame([['ᴀ relatively long ŝtring'], [''], ['']],
34813481
... columns=['strls'])
3482-
>>> writer = StataWriterUTF8('./data_file_with_long_strings.dta', data,
3482+
>>> writer = pd.io.stata.StataWriterUTF8('./data_file_with_long_strings.dta', data,
34833483
... convert_strl=['strls'])
34843484
>>> writer.write_file()
34853485
"""

0 commit comments

Comments
 (0)