Skip to content

Commit f04c994

Browse files
author
aokizy
committed
DOC: Remove unused variables and fix formatting in resample.py
1 parent 058fcab commit f04c994

File tree

1 file changed

+30
-82
lines changed

1 file changed

+30
-82
lines changed

pandas/core/resample.py

Lines changed: 30 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import copy
4-
from textwrap import dedent
4+
55
from typing import (
66
TYPE_CHECKING,
77
Concatenate,
@@ -274,16 +274,15 @@ def pipe(
274274
275275
>>> h = lambda x, arg2, arg3: x + 1 - arg2 * arg3
276276
>>> g = lambda x, arg1: x * 5 / arg1
277-
>>> f = lambda x: x ** 4
277+
>>> f = lambda x: x**4
278278
>>> df = pd.DataFrame([["a", 4], ["b", 5]], columns=["group", "value"])
279-
>>> h(g(f(df.groupby('group')), arg1=1), arg2=2, arg3=3) # doctest: +SKIP
279+
>>> h(g(f(df.groupby("group")), arg1=1), arg2=2, arg3=3) # doctest: +SKIP
280280
281281
You can write
282282
283-
>>> (df.groupby('group')
284-
... .pipe(f)
285-
... .pipe(g, arg1=1)
286-
... .pipe(h, arg2=2, arg3=3)) # doctest: +SKIP
283+
>>> (
284+
... df.groupby("group").pipe(f).pipe(g, arg1=1).pipe(h, arg2=2, arg3=3)
285+
... ) # doctest: +SKIP
287286
288287
which is much more readable.
289288
@@ -318,8 +317,9 @@ def pipe(
318317
319318
Examples
320319
--------
321-
>>> df = pd.DataFrame({'A': [1, 2, 3, 4]},
322-
... index=pd.date_range('2012-08-02', periods=4))
320+
>>> df = pd.DataFrame(
321+
... {"A": [1, 2, 3, 4]}, index=pd.date_range("2012-08-02", periods=4)
322+
... )
323323
>>> df
324324
A
325325
2012-08-02 1
@@ -330,68 +330,12 @@ def pipe(
330330
To get the difference between each 2-day period's maximum and minimum
331331
value in one pass, you can do
332332
333-
>>> df.resample('2D').pipe(lambda x: x.max() - x.min())
333+
>>> df.resample("2D").pipe(lambda x: x.max() - x.min())
334334
A
335335
2012-08-02 1
336336
2012-08-04 1
337337
"""
338338
return super().pipe(func, *args, **kwargs)
339-
340-
_agg_see_also_doc = dedent(
341-
"""
342-
See Also
343-
--------
344-
DataFrame.groupby.aggregate : Aggregate using callable, string, dict,
345-
or list of string/callables.
346-
DataFrame.resample.transform : Transforms the Series on each group
347-
based on the given function.
348-
DataFrame.aggregate: Aggregate using one or more
349-
operations over the specified axis.
350-
"""
351-
)
352-
353-
_agg_examples_doc = dedent(
354-
"""
355-
Examples
356-
--------
357-
>>> s = pd.Series([1, 2, 3, 4, 5],
358-
... index=pd.date_range('20130101', periods=5, freq='s'))
359-
>>> s
360-
2013-01-01 00:00:00 1
361-
2013-01-01 00:00:01 2
362-
2013-01-01 00:00:02 3
363-
2013-01-01 00:00:03 4
364-
2013-01-01 00:00:04 5
365-
Freq: s, dtype: int64
366-
367-
>>> r = s.resample('2s')
368-
369-
>>> r.agg("sum")
370-
2013-01-01 00:00:00 3
371-
2013-01-01 00:00:02 7
372-
2013-01-01 00:00:04 5
373-
Freq: 2s, dtype: int64
374-
375-
>>> r.agg(['sum', 'mean', 'max'])
376-
sum mean max
377-
2013-01-01 00:00:00 3 1.5 2
378-
2013-01-01 00:00:02 7 3.5 4
379-
2013-01-01 00:00:04 5 5.0 5
380-
381-
>>> r.agg({'result': lambda x: x.mean() / x.std(),
382-
... 'total': "sum"})
383-
result total
384-
2013-01-01 00:00:00 2.121320 3
385-
2013-01-01 00:00:02 4.949747 7
386-
2013-01-01 00:00:04 NaN 5
387-
388-
>>> r.agg(average="mean", total="sum")
389-
average total
390-
2013-01-01 00:00:00 1.5 3
391-
2013-01-01 00:00:02 3.5 7
392-
2013-01-01 00:00:04 5.0 5
393-
"""
394-
)
395339

396340
@final
397341
def aggregate(self, func=None, *args, **kwargs):
@@ -455,8 +399,9 @@ def aggregate(self, func=None, *args, **kwargs):
455399
456400
Examples
457401
--------
458-
>>> s = pd.Series([1, 2, 3, 4, 5],
459-
... index=pd.date_range('20130101', periods=5, freq='s'))
402+
>>> s = pd.Series(
403+
... [1, 2, 3, 4, 5], index=pd.date_range("20130101", periods=5, freq="s")
404+
... )
460405
>>> s
461406
2013-01-01 00:00:00 1
462407
2013-01-01 00:00:01 2
@@ -465,22 +410,21 @@ def aggregate(self, func=None, *args, **kwargs):
465410
2013-01-01 00:00:04 5
466411
Freq: s, dtype: int64
467412
468-
>>> r = s.resample('2s')
413+
>>> r = s.resample("2s")
469414
470415
>>> r.agg("sum")
471416
2013-01-01 00:00:00 3
472417
2013-01-01 00:00:02 7
473418
2013-01-01 00:00:04 5
474419
Freq: 2s, dtype: int64
475420
476-
>>> r.agg(['sum', 'mean', 'max'])
421+
>>> r.agg(["sum", "mean", "max"])
477422
sum mean max
478423
2013-01-01 00:00:00 3 1.5 2
479424
2013-01-01 00:00:02 7 3.5 4
480425
2013-01-01 00:00:04 5 5.0 5
481426
482-
>>> r.agg({'result': lambda x: x.mean() / x.std(),
483-
... 'total': "sum"})
427+
>>> r.agg({"result": lambda x: x.mean() / x.std(), "total": "sum"})
484428
result total
485429
2013-01-01 00:00:00 2.121320 3
486430
2013-01-01 00:00:02 4.949747 7
@@ -1402,10 +1346,12 @@ def first(
14021346
14031347
Examples
14041348
--------
1405-
>>> s = pd.Series([1, 2, 3, 4],
1406-
... index=pd.DatetimeIndex(
1407-
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
1408-
... ))
1349+
>>> s = pd.Series(
1350+
... [1, 2, 3, 4],
1351+
... index=pd.DatetimeIndex(
1352+
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
1353+
... ),
1354+
... )
14091355
>>> s
14101356
2023-01-01 1
14111357
2023-01-15 2
@@ -1453,10 +1399,12 @@ def last(
14531399
14541400
Examples
14551401
--------
1456-
>>> s = pd.Series([1, 2, 3, 4],
1457-
... index=pd.DatetimeIndex(
1458-
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
1459-
... ))
1402+
>>> s = pd.Series(
1403+
... [1, 2, 3, 4],
1404+
... index=pd.DatetimeIndex(
1405+
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
1406+
... ),
1407+
... )
14601408
>>> s
14611409
2023-01-01 1
14621410
2023-01-15 2
@@ -1859,7 +1807,7 @@ def size(self):
18591807
--------
18601808
Series.groupby : Apply a function groupby to a Series.
18611809
DataFrame.groupby : Apply a function groupby to each row
1862-
or column of a DataFrame.
1810+
or column of a DataFrame.
18631811
18641812
Examples
18651813
--------
@@ -1908,7 +1856,7 @@ def count(self):
19081856
--------
19091857
Series.groupby : Apply a function groupby to a Series.
19101858
DataFrame.groupby : Apply a function groupby to each row
1911-
or column of a DataFrame.
1859+
or column of a DataFrame.
19121860
19131861
Examples
19141862
--------

0 commit comments

Comments
 (0)