@@ -2314,38 +2314,12 @@ def cov(self, other, min_periods=None) -> float:
2314
2314
return np .nan
2315
2315
return nanops .nancov (this .values , other .values , min_periods = min_periods )
2316
2316
2317
- def diff (self , periods : int = 1 ) -> "Series" :
2318
- """
2319
- First discrete difference of element.
2320
-
2321
- Calculates the difference of a Series element compared with another
2322
- element in the Series (default is element in previous row).
2323
-
2324
- Parameters
2325
- ----------
2326
- periods : int, default 1
2327
- Periods to shift for calculating difference, accepts negative
2328
- values.
2329
-
2330
- Returns
2331
- -------
2332
- Series
2333
- First differences of the Series.
2334
-
2335
- See Also
2336
- --------
2337
- Series.pct_change: Percent change over given number of periods.
2338
- Series.shift: Shift index by desired number of periods with an
2339
- optional time freq.
2340
- DataFrame.diff: First discrete difference of object.
2341
-
2342
- Notes
2343
- -----
2344
- For boolean dtypes, this uses :meth:`operator.xor` rather than
2345
- :meth:`operator.sub`.
2346
-
2347
- Examples
2348
- --------
2317
+ @doc (
2318
+ klass = "Series" ,
2319
+ extra_params = "" ,
2320
+ other_klass = "DataFrame" ,
2321
+ examples = dedent (
2322
+ """
2349
2323
Difference with previous row
2350
2324
2351
2325
>>> s = pd.Series([1, 1, 2, 3, 5, 8])
@@ -2379,6 +2353,51 @@ def diff(self, periods: int = 1) -> "Series":
2379
2353
4 -3.0
2380
2354
5 NaN
2381
2355
dtype: float64
2356
+
2357
+ Overflow in input dtype
2358
+
2359
+ >>> s = pd.Series([1, 0], dtype=np.uint8)
2360
+ >>> s.diff()
2361
+ 0 NaN
2362
+ 1 255.0
2363
+ dtype: float64"""
2364
+ ),
2365
+ )
2366
+ def diff (self , periods : int = 1 ) -> "Series" :
2367
+ """
2368
+ First discrete difference of element.
2369
+
2370
+ Calculates the difference of a {klass} element compared with another
2371
+ element in the {klass} (default is element in previous row).
2372
+
2373
+ Parameters
2374
+ ----------
2375
+ periods : int, default 1
2376
+ Periods to shift for calculating difference, accepts negative
2377
+ values.
2378
+ {extra_params}
2379
+ Returns
2380
+ -------
2381
+ {klass}
2382
+ First differences of the Series.
2383
+
2384
+ See Also
2385
+ --------
2386
+ {klass}.pct_change: Percent change over given number of periods.
2387
+ {klass}.shift: Shift index by desired number of periods with an
2388
+ optional time freq.
2389
+ {other_klass}.diff: First discrete difference of object.
2390
+
2391
+ Notes
2392
+ -----
2393
+ For boolean dtypes, this uses :meth:`operator.xor` rather than
2394
+ :meth:`operator.sub`.
2395
+ The result is calculated according to current dtype in {klass},
2396
+ however dtype of the result is always float64.
2397
+
2398
+ Examples
2399
+ --------
2400
+ {examples}
2382
2401
"""
2383
2402
result = algorithms .diff (self .array , periods )
2384
2403
return self ._constructor (result , index = self .index ).__finalize__ (
0 commit comments