@@ -964,32 +964,36 @@ def test_monotonic(self):
964
964
datas .append ([(- 5 , "e" ), (- 3 , "d" ), (- 2 , "c" ), (- 4 , "b" ), (- 1 , "a" )])
965
965
datas .append ([(- 5 , "e" ), (- 4 , "c" ), (- 3 , "b" ), (- 2 , "d" ), (- 1 , "a" )])
966
966
967
- # None type tests (None type is treated as the smallest value)
968
- datas .append ([(1 , 100 ), (2 , 200 ), (None , 300 ), (4 , 400 ), (5 , 500 )])
969
- datas .append ([(5 , None ), (4 , 200 ), (3 , 300 ), (2 , 400 ), (1 , 500 )])
970
- datas .append ([(5 , 100 ), (4 , 200 ), (3 , None ), (2 , 400 ), (1 , 500 )])
971
- datas .append ([(5 , 100 ), (4 , 200 ), (3 , 300 ), (2 , 400 ), (1 , None )])
972
- datas .append ([(1 , 100 ), (2 , 200 ), (None , None ), (4 , 400 ), (5 , 500 )])
973
- # The datas below cannot be an arguments for `MultiIndex.from_tuples` in pandas >= 1.1.0.
974
- # Refer https://github.com/databricks/koalas/pull/1688#issuecomment-667156560 for detail.
975
- if LooseVersion (pd .__version__ ) < LooseVersion ("1.1.0" ):
976
- datas .append ([(- 5 , None ), (- 4 , None ), (- 3 , None ), (- 2 , None ), (- 1 , None )])
977
- datas .append ([(None , "e" ), (None , "c" ), (None , "b" ), (None , "d" ), (None , "a" )])
978
- datas .append ([(None , None ), (None , None ), (None , None ), (None , None ), (None , None )])
967
+ # boolean type tests
968
+ datas .append ([(True , True ), (True , True )])
969
+ datas .append ([(True , True ), (True , False )])
970
+ datas .append ([(True , False ), (True , True )])
971
+ datas .append ([(False , True ), (False , True )])
972
+ datas .append ([(False , True ), (False , False )])
973
+ datas .append ([(False , False ), (False , True )])
974
+ datas .append ([(True , True ), (False , True )])
975
+ datas .append ([(True , True ), (False , False )])
976
+ datas .append ([(True , False ), (False , True )])
977
+ datas .append ([(False , True ), (True , True )])
978
+ datas .append ([(False , True ), (True , False )])
979
+ datas .append ([(False , False ), (True , True )])
979
980
980
981
# duplicated index value tests
981
982
datas .append ([("x" , "d" ), ("y" , "c" ), ("y" , "b" ), ("z" , "a" )])
982
983
datas .append ([("x" , "d" ), ("y" , "b" ), ("y" , "c" ), ("z" , "a" )])
983
- datas .append ([("x" , "d" ), ("y" , "c" ), ("y" , None ), ("z" , "a" )])
984
- datas .append ([("x" , "d" ), ("y" , None ), ("y" , None ), ("z" , "a" )])
985
- datas .append ([("x" , "d" ), ("y" , "c" ), ("y" , "b" ), (None , "a" )])
986
- datas .append ([("x" , "d" ), ("y" , "b" ), ("y" , "c" ), (None , "a" )])
987
984
988
985
# more depth tests
989
986
datas .append ([("x" , "d" , "o" ), ("y" , "c" , "p" ), ("y" , "c" , "q" ), ("z" , "a" , "r" )])
990
987
datas .append ([("x" , "d" , "o" ), ("y" , "c" , "q" ), ("y" , "c" , "p" ), ("z" , "a" , "r" )])
988
+
989
+ # None type tests (None type is treated as False from pandas >= 1.1.4)
990
+ # Refer https://github.com/pandas-dev/pandas/issues/37220
991
+ datas .append ([(1 , 100 ), (2 , 200 ), (None , 300 ), (4 , 400 ), (5 , 500 )])
992
+ datas .append ([(1 , 100 ), (2 , 200 ), (None , None ), (4 , 400 ), (5 , 500 )])
993
+ datas .append ([("x" , "d" ), ("y" , "c" ), ("y" , None ), ("z" , "a" )])
994
+ datas .append ([("x" , "d" ), ("y" , "c" ), ("y" , "b" ), (None , "a" )])
995
+ datas .append ([("x" , "d" ), ("y" , "b" ), ("y" , "c" ), (None , "a" )])
991
996
datas .append ([("x" , "d" , "o" ), ("y" , "c" , "p" ), ("y" , "c" , None ), ("z" , "a" , "r" )])
992
- datas .append ([("x" , "d" , "o" ), ("y" , "c" , None ), ("y" , "c" , None ), ("z" , "a" , "r" )])
993
997
994
998
for data in datas :
995
999
with self .subTest (data = data ):
@@ -998,25 +1002,105 @@ def test_monotonic(self):
998
1002
self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
999
1003
self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1000
1004
1001
- # The datas below are showing different result depends on pandas version.
1002
- # Because the behavior of handling null values is changed in pandas >= 1.0.0.
1005
+ # datas below return different result depends on pandas version.
1006
+ # Because the behavior of handling null values is changed in pandas >= 1.1.4.
1007
+ # Since Koalas follows latest pandas, all of them should return `False`.
1003
1008
datas = []
1004
- datas .append ([(None , 100 ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , 500 )])
1009
+ datas .append ([(1 , 100 ), (2 , 200 ), (3 , None ), (4 , 400 ), (5 , 500 )])
1010
+ datas .append ([(1 , None ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , 500 )])
1011
+ datas .append ([(1 , 100 ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , None )])
1012
+ datas .append ([(False , None ), (True , True )])
1013
+ datas .append ([(None , False ), (True , True )])
1014
+ datas .append ([(False , False ), (True , None )])
1015
+ datas .append ([(False , False ), (None , True )])
1016
+ datas .append ([("x" , "d" ), ("y" , None ), ("y" , None ), ("z" , "a" )])
1017
+ datas .append ([("x" , "d" , "o" ), ("y" , "c" , None ), ("y" , "c" , None ), ("z" , "a" , "r" )])
1005
1018
datas .append ([(1 , 100 ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (None , 500 )])
1006
- datas .append ([(None , None ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , 500 )])
1007
1019
datas .append ([(1 , 100 ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (None , None )])
1020
+ datas .append ([(5 , 100 ), (4 , 200 ), (3 , None ), (2 , 400 ), (1 , 500 )])
1021
+ datas .append ([(5 , None ), (4 , 200 ), (3 , 300 ), (2 , 400 ), (1 , 500 )])
1022
+ datas .append ([(5 , 100 ), (4 , 200 ), (3 , None ), (2 , 400 ), (1 , 500 )])
1023
+ datas .append ([(5 , 100 ), (4 , 200 ), (3 , 300 ), (2 , 400 ), (1 , None )])
1024
+ datas .append ([(True , None ), (True , True )])
1025
+ datas .append ([(None , True ), (True , True )])
1026
+ datas .append ([(True , True ), (None , True )])
1027
+ datas .append ([(True , True ), (True , None )])
1028
+ datas .append ([(None , 100 ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , 500 )])
1029
+ datas .append ([(None , None ), (2 , 200 ), (3 , 300 ), (4 , 400 ), (5 , 500 )])
1008
1030
datas .append ([("x" , "d" ), ("y" , None ), ("y" , "c" ), ("z" , "a" )])
1009
1031
datas .append ([("x" , "d" , "o" ), ("y" , "c" , None ), ("y" , "c" , "q" ), ("z" , "a" , "r" )])
1010
1032
1011
1033
for data in datas :
1012
1034
with self .subTest (data = data ):
1013
1035
pmidx = pd .MultiIndex .from_tuples (data )
1014
1036
kmidx = ks .from_pandas (pmidx )
1015
- expected_increasing_result = pmidx .is_monotonic_increasing
1016
- if LooseVersion (pd .__version__ ) < LooseVersion ("1.0.0" ):
1017
- expected_increasing_result = not expected_increasing_result
1018
- self .assert_eq (kmidx .is_monotonic_increasing , expected_increasing_result )
1019
- self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1037
+ if LooseVersion (pd .__version__ ) < LooseVersion ("1.1.4" ):
1038
+ self .assert_eq (kmidx .is_monotonic_increasing , False )
1039
+ self .assert_eq (kmidx .is_monotonic_decreasing , False )
1040
+ else :
1041
+ self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
1042
+ self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1043
+
1044
+ # The datas below are tested another way since they cannot be an arguments for
1045
+ # `MultiIndex.from_tuples` in pandas >= 1.1.0.
1046
+ # Refer https://github.com/databricks/koalas/pull/1688#issuecomment-667156560 for detail.
1047
+ if LooseVersion (pd .__version__ ) < LooseVersion ("1.1.0" ):
1048
+ pmidx = pd .MultiIndex .from_tuples (
1049
+ [(- 5 , None ), (- 4 , None ), (- 3 , None ), (- 2 , None ), (- 1 , None )]
1050
+ )
1051
+ kmidx = ks .from_pandas (pmidx )
1052
+ self .assert_eq (kmidx .is_monotonic_increasing , False )
1053
+ self .assert_eq (kmidx .is_monotonic_decreasing , False )
1054
+
1055
+ pmidx = pd .MultiIndex .from_tuples (
1056
+ [(None , "e" ), (None , "c" ), (None , "b" ), (None , "d" ), (None , "a" )]
1057
+ )
1058
+ kmidx = ks .from_pandas (pmidx )
1059
+ self .assert_eq (kmidx .is_monotonic_increasing , False )
1060
+ self .assert_eq (kmidx .is_monotonic_decreasing , False )
1061
+
1062
+ pmidx = pd .MultiIndex .from_tuples (
1063
+ [(None , None ), (None , None ), (None , None ), (None , None ), (None , None )]
1064
+ )
1065
+ kmidx = ks .from_pandas (pmidx )
1066
+ self .assert_eq (kmidx .is_monotonic_increasing , False )
1067
+ self .assert_eq (kmidx .is_monotonic_decreasing , False )
1068
+
1069
+ pmidx = pd .MultiIndex .from_tuples ([(None , None )])
1070
+ kmidx = ks .from_pandas (pmidx )
1071
+ self .assert_eq (kmidx .is_monotonic_increasing , False )
1072
+ self .assert_eq (kmidx .is_monotonic_decreasing , False )
1073
+ else :
1074
+ # [(-5, None), (-4, None), (-3, None), (-2, None), (-1, None)]
1075
+ kdf = ks .DataFrame ({"a" : [- 5 , - 4 , - 3 , - 2 , - 1 ], "b" : [1 , 1 , 1 , 1 , 1 ]})
1076
+ kdf ["b" ] = None
1077
+ kmidx = kdf .set_index (["a" , "b" ]).index
1078
+ pmidx = kmidx .to_pandas ()
1079
+ self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
1080
+ self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1081
+ # [(None, "e"), (None, "c"), (None, "b"), (None, "d"), (None, "a")]
1082
+ kdf = ks .DataFrame ({"a" : [1 , 1 , 1 , 1 , 1 ], "b" : ["e" , "c" , "b" , "d" , "a" ]})
1083
+ kdf ["a" ] = None
1084
+ kmidx = kdf .set_index (["a" , "b" ]).index
1085
+ pmidx = kmidx .to_pandas ()
1086
+ self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
1087
+ self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1088
+ # [(None, None), (None, None), (None, None), (None, None), (None, None)]
1089
+ kdf = ks .DataFrame ({"a" : [1 , 1 , 1 , 1 , 1 ], "b" : [1 , 1 , 1 , 1 , 1 ]})
1090
+ kdf ["a" ] = None
1091
+ kdf ["b" ] = None
1092
+ kmidx = kdf .set_index (["a" , "b" ]).index
1093
+ pmidx = kmidx .to_pandas ()
1094
+ self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
1095
+ self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1096
+ # [(None, None)]
1097
+ kdf = ks .DataFrame ({"a" : [1 ], "b" : [1 ]})
1098
+ kdf ["a" ] = None
1099
+ kdf ["b" ] = None
1100
+ kmidx = kdf .set_index (["a" , "b" ]).index
1101
+ pmidx = kmidx .to_pandas ()
1102
+ self .assert_eq (kmidx .is_monotonic_increasing , pmidx .is_monotonic_increasing )
1103
+ self .assert_eq (kmidx .is_monotonic_decreasing , pmidx .is_monotonic_decreasing )
1020
1104
1021
1105
def test_difference (self ):
1022
1106
# Index
0 commit comments