|
27 | 27 | from pyspark import sql as spark
|
28 | 28 | from pyspark.sql import functions as F, Window
|
29 | 29 | from pyspark.sql.types import DoubleType, FloatType, LongType, StringType, TimestampType
|
| 30 | +from pyspark.sql.functions import monotonically_increasing_id |
30 | 31 |
|
31 | 32 | from databricks import koalas as ks # For running doctests and reference resolution in PyCharm.
|
32 | 33 | from databricks.koalas.internal import _InternalFrame
|
@@ -299,9 +300,16 @@ def is_monotonic(self):
|
299 | 300 |
|
300 | 301 | >>> ser.rename("a").to_frame().set_index("a").index.is_monotonic
|
301 | 302 | True
|
| 303 | +
|
| 304 | + >>> ser = ks.Series([5, 4, 3, 2, 1], index=[1, 2, 3, 4, 5]) |
| 305 | + >>> ser.is_monotonic |
| 306 | + False |
| 307 | +
|
| 308 | + >>> ser.index.is_monotonic |
| 309 | + True |
302 | 310 | """
|
303 | 311 | col = self._scol
|
304 |
| - window = Window.orderBy(self._kdf._internal.index_scols).rowsBetween(-1, -1) |
| 312 | + window = Window.orderBy(monotonically_increasing_id()).rowsBetween(-1, -1) |
305 | 313 | return self._with_new_scol((col >= F.lag(col, 1).over(window)) & col.isNotNull()).all()
|
306 | 314 |
|
307 | 315 | is_monotonic_increasing = is_monotonic
|
@@ -343,9 +351,16 @@ def is_monotonic_decreasing(self):
|
343 | 351 |
|
344 | 352 | >>> ser.rename("a").to_frame().set_index("a").index.is_monotonic_decreasing
|
345 | 353 | True
|
| 354 | +
|
| 355 | + >>> ser = ks.Series([5, 4, 3, 2, 1], index=[1, 2, 3, 4, 5]) |
| 356 | + >>> ser.is_monotonic_decreasing |
| 357 | + True |
| 358 | +
|
| 359 | + >>> ser.index.is_monotonic_decreasing |
| 360 | + False |
346 | 361 | """
|
347 | 362 | col = self._scol
|
348 |
| - window = Window.orderBy(self._kdf._internal.index_scols).rowsBetween(-1, -1) |
| 363 | + window = Window.orderBy(monotonically_increasing_id()).rowsBetween(-1, -1) |
349 | 364 | return self._with_new_scol((col <= F.lag(col, 1).over(window)) & col.isNotNull()).all()
|
350 | 365 |
|
351 | 366 | def astype(self, dtype):
|
|
0 commit comments