Skip to content

Commit 873092d

Browse files
Daniel SaxtonPingviinituutti
Daniel Saxton
authored andcommitted
DOC/CLN: Fix various docstring errors (pandas-dev#25295)
1 parent 0a88ee7 commit 873092d

File tree

10 files changed

+232
-211
lines changed

10 files changed

+232
-211
lines changed

pandas/core/arrays/categorical.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def contains(cat, key, container):
214214

215215
class Categorical(ExtensionArray, PandasObject):
216216
"""
217-
Represent a categorical variable in classic R / S-plus fashion
217+
Represent a categorical variable in classic R / S-plus fashion.
218218
219219
`Categoricals` can only take on only a limited, and usually fixed, number
220220
of possible values (`categories`). In contrast to statistical categorical
@@ -235,7 +235,7 @@ class Categorical(ExtensionArray, PandasObject):
235235
The unique categories for this categorical. If not given, the
236236
categories are assumed to be the unique values of `values` (sorted, if
237237
possible, otherwise in the order in which they appear).
238-
ordered : boolean, (default False)
238+
ordered : bool, default False
239239
Whether or not this categorical is treated as a ordered categorical.
240240
If True, the resulting categorical will be ordered.
241241
An ordered categorical respects, when sorted, the order of its
@@ -253,7 +253,7 @@ class Categorical(ExtensionArray, PandasObject):
253253
codes : ndarray
254254
The codes (integer positions, which point to the categories) of this
255255
categorical, read only.
256-
ordered : boolean
256+
ordered : bool
257257
Whether or not this Categorical is ordered.
258258
dtype : CategoricalDtype
259259
The instance of ``CategoricalDtype`` storing the ``categories``
@@ -297,7 +297,7 @@ class Categorical(ExtensionArray, PandasObject):
297297
Ordered `Categoricals` can be sorted according to the custom order
298298
of the categories and can have a min and max value.
299299
300-
>>> c = pd.Categorical(['a','b','c','a','b','c'], ordered=True,
300+
>>> c = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'], ordered=True,
301301
... categories=['c', 'b', 'a'])
302302
>>> c
303303
[a, b, c, a, b, c]
@@ -618,7 +618,7 @@ def from_codes(cls, codes, categories=None, ordered=None, dtype=None):
618618
----------
619619
codes : array-like, integers
620620
An integer array, where each integer points to a category in
621-
categories or dtype.categories, or else is -1 for NaN
621+
categories or dtype.categories, or else is -1 for NaN.
622622
categories : index-like, optional
623623
The categories for the categorical. Items need to be unique.
624624
If the categories are not given here, then they must be provided
@@ -700,7 +700,7 @@ def _set_categories(self, categories, fastpath=False):
700700
701701
Parameters
702702
----------
703-
fastpath : boolean (default: False)
703+
fastpath : bool, default False
704704
Don't perform validation of the categories for uniqueness or nulls
705705
706706
Examples
@@ -747,15 +747,15 @@ def _set_dtype(self, dtype):
747747

748748
def set_ordered(self, value, inplace=False):
749749
"""
750-
Set the ordered attribute to the boolean value
750+
Set the ordered attribute to the boolean value.
751751
752752
Parameters
753753
----------
754-
value : boolean to set whether this categorical is ordered (True) or
755-
not (False)
756-
inplace : boolean (default: False)
757-
Whether or not to set the ordered attribute inplace or return a copy
758-
of this categorical with ordered set to the value
754+
value : bool
755+
Set whether this categorical is ordered (True) or not (False).
756+
inplace : bool, default False
757+
Whether or not to set the ordered attribute in-place or return
758+
a copy of this categorical with ordered set to the value.
759759
"""
760760
inplace = validate_bool_kwarg(inplace, 'inplace')
761761
new_dtype = CategoricalDtype(self.categories, ordered=value)
@@ -770,9 +770,9 @@ def as_ordered(self, inplace=False):
770770
771771
Parameters
772772
----------
773-
inplace : boolean (default: False)
774-
Whether or not to set the ordered attribute inplace or return a copy
775-
of this categorical with ordered set to True
773+
inplace : bool, default False
774+
Whether or not to set the ordered attribute in-place or return
775+
a copy of this categorical with ordered set to True.
776776
"""
777777
inplace = validate_bool_kwarg(inplace, 'inplace')
778778
return self.set_ordered(True, inplace=inplace)
@@ -783,9 +783,9 @@ def as_unordered(self, inplace=False):
783783
784784
Parameters
785785
----------
786-
inplace : boolean (default: False)
787-
Whether or not to set the ordered attribute inplace or return a copy
788-
of this categorical with ordered set to False
786+
inplace : bool, default False
787+
Whether or not to set the ordered attribute in-place or return
788+
a copy of this categorical with ordered set to False.
789789
"""
790790
inplace = validate_bool_kwarg(inplace, 'inplace')
791791
return self.set_ordered(False, inplace=inplace)
@@ -815,19 +815,19 @@ def set_categories(self, new_categories, ordered=None, rename=False,
815815
----------
816816
new_categories : Index-like
817817
The categories in new order.
818-
ordered : boolean, (default: False)
818+
ordered : bool, default False
819819
Whether or not the categorical is treated as a ordered categorical.
820820
If not given, do not change the ordered information.
821-
rename : boolean (default: False)
821+
rename : bool, default False
822822
Whether or not the new_categories should be considered as a rename
823823
of the old categories or as reordered categories.
824-
inplace : boolean (default: False)
825-
Whether or not to reorder the categories inplace or return a copy of
826-
this categorical with reordered categories.
824+
inplace : bool, default False
825+
Whether or not to reorder the categories in-place or return a copy
826+
of this categorical with reordered categories.
827827
828828
Returns
829829
-------
830-
cat : Categorical with reordered categories or None if inplace.
830+
Categorical with reordered categories or None if inplace.
831831
832832
Raises
833833
------
@@ -890,7 +890,7 @@ def rename_categories(self, new_categories, inplace=False):
890890
Currently, Series are considered list like. In a future version
891891
of pandas they'll be considered dict-like.
892892
893-
inplace : boolean (default: False)
893+
inplace : bool, default False
894894
Whether or not to rename the categories inplace or return a copy of
895895
this categorical with renamed categories.
896896
@@ -967,10 +967,10 @@ def reorder_categories(self, new_categories, ordered=None, inplace=False):
967967
----------
968968
new_categories : Index-like
969969
The categories in new order.
970-
ordered : boolean, optional
970+
ordered : bool, optional
971971
Whether or not the categorical is treated as a ordered categorical.
972972
If not given, do not change the ordered information.
973-
inplace : boolean (default: False)
973+
inplace : bool, default False
974974
Whether or not to reorder the categories inplace or return a copy of
975975
this categorical with reordered categories.
976976
@@ -1010,7 +1010,7 @@ def add_categories(self, new_categories, inplace=False):
10101010
----------
10111011
new_categories : category or list-like of category
10121012
The new categories to be included.
1013-
inplace : boolean (default: False)
1013+
inplace : bool, default False
10141014
Whether or not to add the categories inplace or return a copy of
10151015
this categorical with added categories.
10161016
@@ -1060,7 +1060,7 @@ def remove_categories(self, removals, inplace=False):
10601060
----------
10611061
removals : category or list of categories
10621062
The categories which should be removed.
1063-
inplace : boolean (default: False)
1063+
inplace : bool, default False
10641064
Whether or not to remove the categories inplace or return a copy of
10651065
this categorical with removed categories.
10661066
@@ -1108,7 +1108,7 @@ def remove_unused_categories(self, inplace=False):
11081108
11091109
Parameters
11101110
----------
1111-
inplace : boolean (default: False)
1111+
inplace : bool, default False
11121112
Whether or not to drop unused categories inplace or return a copy of
11131113
this categorical with unused categories dropped.
11141114
@@ -1460,7 +1460,7 @@ def value_counts(self, dropna=True):
14601460
14611461
Parameters
14621462
----------
1463-
dropna : boolean, default True
1463+
dropna : bool, default True
14641464
Don't include counts of NaN.
14651465
14661466
Returns
@@ -1581,9 +1581,9 @@ def sort_values(self, inplace=False, ascending=True, na_position='last'):
15811581
15821582
Parameters
15831583
----------
1584-
inplace : boolean, default False
1584+
inplace : bool, default False
15851585
Do operation in place.
1586-
ascending : boolean, default True
1586+
ascending : bool, default True
15871587
Order ascending. Passing False orders descending. The
15881588
ordering parameter provides the method by which the
15891589
category values are organized.
@@ -2239,7 +2239,7 @@ def mode(self, dropna=True):
22392239
22402240
Parameters
22412241
----------
2242-
dropna : boolean, default True
2242+
dropna : bool, default True
22432243
Don't consider counts of NaN/NaT.
22442244
22452245
.. versionadded:: 0.24.0
@@ -2332,7 +2332,7 @@ def equals(self, other):
23322332
23332333
Returns
23342334
-------
2335-
are_equal : boolean
2335+
bool
23362336
"""
23372337
if self.is_dtype_equal(other):
23382338
if self.categories.equals(other.categories):
@@ -2356,7 +2356,7 @@ def is_dtype_equal(self, other):
23562356
23572357
Returns
23582358
-------
2359-
are_equal : boolean
2359+
bool
23602360
"""
23612361

23622362
try:

pandas/core/arrays/datetimes.py

+30-34
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,14 @@ def tz_convert(self, tz):
799799
800800
Parameters
801801
----------
802-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
802+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
803803
Time zone for time. Corresponding timestamps would be converted
804804
to this time zone of the Datetime Array/Index. A `tz` of None will
805805
convert to UTC and remove the timezone information.
806806
807807
Returns
808808
-------
809-
normalized : same type as self
809+
Array or Index
810810
811811
Raises
812812
------
@@ -842,7 +842,7 @@ def tz_convert(self, tz):
842842
With the ``tz=None``, we can remove the timezone (after converting
843843
to UTC if necessary):
844844
845-
>>> dti = pd.date_range(start='2014-08-01 09:00',freq='H',
845+
>>> dti = pd.date_range(start='2014-08-01 09:00', freq='H',
846846
... periods=3, tz='Europe/Berlin')
847847
848848
>>> dti
@@ -882,7 +882,7 @@ def tz_localize(self, tz, ambiguous='raise', nonexistent='raise',
882882
883883
Parameters
884884
----------
885-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
885+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
886886
Time zone to convert timestamps to. Passing ``None`` will
887887
remove the time zone information preserving local time.
888888
ambiguous : 'infer', 'NaT', bool array, default 'raise'
@@ -930,7 +930,7 @@ def tz_localize(self, tz, ambiguous='raise', nonexistent='raise',
930930
931931
Returns
932932
-------
933-
result : same type as self
933+
Same type as self
934934
Array/Index converted to the specified time zone.
935935
936936
Raises
@@ -970,43 +970,39 @@ def tz_localize(self, tz, ambiguous='raise', nonexistent='raise',
970970
971971
Be careful with DST changes. When there is sequential data, pandas can
972972
infer the DST time:
973-
>>> s = pd.to_datetime(pd.Series([
974-
... '2018-10-28 01:30:00',
975-
... '2018-10-28 02:00:00',
976-
... '2018-10-28 02:30:00',
977-
... '2018-10-28 02:00:00',
978-
... '2018-10-28 02:30:00',
979-
... '2018-10-28 03:00:00',
980-
... '2018-10-28 03:30:00']))
973+
>>> s = pd.to_datetime(pd.Series(['2018-10-28 01:30:00',
974+
... '2018-10-28 02:00:00',
975+
... '2018-10-28 02:30:00',
976+
... '2018-10-28 02:00:00',
977+
... '2018-10-28 02:30:00',
978+
... '2018-10-28 03:00:00',
979+
... '2018-10-28 03:30:00']))
981980
>>> s.dt.tz_localize('CET', ambiguous='infer')
982-
2018-10-28 01:30:00+02:00 0
983-
2018-10-28 02:00:00+02:00 1
984-
2018-10-28 02:30:00+02:00 2
985-
2018-10-28 02:00:00+01:00 3
986-
2018-10-28 02:30:00+01:00 4
987-
2018-10-28 03:00:00+01:00 5
988-
2018-10-28 03:30:00+01:00 6
989-
dtype: int64
981+
0 2018-10-28 01:30:00+02:00
982+
1 2018-10-28 02:00:00+02:00
983+
2 2018-10-28 02:30:00+02:00
984+
3 2018-10-28 02:00:00+01:00
985+
4 2018-10-28 02:30:00+01:00
986+
5 2018-10-28 03:00:00+01:00
987+
6 2018-10-28 03:30:00+01:00
988+
dtype: datetime64[ns, CET]
990989
991990
In some cases, inferring the DST is impossible. In such cases, you can
992991
pass an ndarray to the ambiguous parameter to set the DST explicitly
993992
994-
>>> s = pd.to_datetime(pd.Series([
995-
... '2018-10-28 01:20:00',
996-
... '2018-10-28 02:36:00',
997-
... '2018-10-28 03:46:00']))
993+
>>> s = pd.to_datetime(pd.Series(['2018-10-28 01:20:00',
994+
... '2018-10-28 02:36:00',
995+
... '2018-10-28 03:46:00']))
998996
>>> s.dt.tz_localize('CET', ambiguous=np.array([True, True, False]))
999-
0 2018-10-28 01:20:00+02:00
1000-
1 2018-10-28 02:36:00+02:00
1001-
2 2018-10-28 03:46:00+01:00
1002-
dtype: datetime64[ns, CET]
997+
0 2015-03-29 03:00:00+02:00
998+
1 2015-03-29 03:30:00+02:00
999+
dtype: datetime64[ns, Europe/Warsaw]
10031000
10041001
If the DST transition causes nonexistent times, you can shift these
10051002
dates forward or backwards with a timedelta object or `'shift_forward'`
10061003
or `'shift_backwards'`.
1007-
>>> s = pd.to_datetime(pd.Series([
1008-
... '2015-03-29 02:30:00',
1009-
... '2015-03-29 03:30:00']))
1004+
>>> s = pd.to_datetime(pd.Series(['2015-03-29 02:30:00',
1005+
... '2015-03-29 03:30:00']))
10101006
>>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_forward')
10111007
0 2015-03-29 03:00:00+02:00
10121008
1 2015-03-29 03:30:00+02:00
@@ -1129,7 +1125,7 @@ def to_period(self, freq=None):
11291125
11301126
Parameters
11311127
----------
1132-
freq : string or Offset, optional
1128+
freq : str or Offset, optional
11331129
One of pandas' :ref:`offset strings <timeseries.offset_aliases>`
11341130
or an Offset object. Will be inferred by default.
11351131
@@ -1150,7 +1146,7 @@ def to_period(self, freq=None):
11501146
11511147
Examples
11521148
--------
1153-
>>> df = pd.DataFrame({"y": [1,2,3]},
1149+
>>> df = pd.DataFrame({"y": [1, 2, 3]},
11541150
... index=pd.to_datetime(["2000-03-31 00:00:00",
11551151
... "2000-05-31 00:00:00",
11561152
... "2000-08-31 00:00:00"]))

0 commit comments

Comments
 (0)