@@ -345,6 +345,195 @@ def base_test_regular_expressions(self):
345345 ],
346346 )
347347
348+ def base_test_is_unique (self ):
349+ unique_column = ta .column (
350+ [f"test{ x } " for x in range (3 )],
351+ device = self .device ,
352+ )
353+
354+ self .assertTrue (unique_column .is_unique )
355+
356+ non_unique_column = ta .column (
357+ [
358+ "test" ,
359+ "test" ,
360+ ],
361+ device = self .device ,
362+ )
363+
364+ self .assertFalse (non_unique_column .is_unique )
365+
366+ def base_test_is_monotonic_increasing (self ):
367+ c = ta .column ([f"test{ x } " for x in range (5 )], device = self .device )
368+ self .assertTrue (c .is_monotonic_increasing )
369+ self .assertFalse (c .is_monotonic_decreasing )
370+
371+ def base_test_is_monotonic_decreasing (self ):
372+ c = ta .column ([f"test{ x } " for x in range (5 , 0 , - 1 )], device = self .device )
373+ self .assertFalse (c .is_monotonic_increasing )
374+ self .assertTrue (c .is_monotonic_decreasing )
375+
376+ def base_test_if_else (self ):
377+ left_repr = ["a1" , "a2" , "a3" , "a4" ]
378+ right_repr = ["b1" , "b2" , "b3" , "b4" ]
379+ float_type = ta .column (
380+ [1.22 , 2.22 , 3.22 , 4.22 ], dtype = dt .float32 , device = self .device
381+ )
382+ cond_repr = [True , False , True , False ]
383+ cond = ta .column (cond_repr , device = self .device )
384+ left = ta .column (left_repr , device = self .device )
385+ right = ta .column (right_repr , device = self .device )
386+
387+ # Ensure py-iterables work as intended
388+ expected = [left_repr [0 ], right_repr [1 ], left_repr [2 ], right_repr [3 ]]
389+ result = ta .if_else (cond , left_repr , right_repr )
390+ self .assertEqual (expected , list (result ))
391+
392+ # Non common dtype
393+ with self .assertRaisesRegex (
394+ expected_exception = TypeError ,
395+ expected_regex = "then and else branches must have compatible types, got.*and.*, respectively" ,
396+ ):
397+ ta .if_else (cond , left , float_type )
398+
399+ # Invalid condition input
400+ with self .assertRaisesRegex (
401+ expected_exception = TypeError ,
402+ expected_regex = "condition must be a boolean vector" ,
403+ ):
404+ ta .if_else (
405+ cond = left ,
406+ left = left ,
407+ right = right ,
408+ )
409+
410+ def base_test_str (self ):
411+ c = ta .column ([f"test{ x } " for x in range (5 )], device = self .device )
412+
413+ expected = "Column(['test0', 'test1', 'test2', 'test3', 'test4'])"
414+ self .assertEqual (expected , str (c ))
415+
416+ def base_test_repr (self ):
417+ c = ta .column ([f"test{ x } " for x in range (5 )], device = self .device )
418+
419+ expected = (
420+ "0 'test0'\n "
421+ "1 'test1'\n "
422+ "2 'test2'\n "
423+ "3 'test3'\n "
424+ "4 'test4'\n "
425+ f"dtype: string, length: 5, null_count: 0, device: { self .device } "
426+ )
427+ self .assertEqual (expected , repr (c ))
428+
429+ def base_test_is_valid_at (self ):
430+ c = ta .column ([f"test{ x } " for x in range (5 )], device = self .device )
431+
432+ self .assertTrue (all (c .is_valid_at (x ) for x in range (5 )))
433+
434+ def base_test_cast (self ):
435+ c_repr = ["0" , "1" , "2" , "3" , "4" , None ]
436+ c_repr_after_cast = [0 , 1 , 2 , 3 , 4 , None ]
437+ c = ta .column (c_repr , device = self .device )
438+
439+ result = c .cast (dt .int64 )
440+ self .assertEqual (c_repr_after_cast , list (result ))
441+
442+ def base_test_drop_null (self ):
443+ c_repr = ["0" , "1" , "2" , "3" , "4" , None ]
444+ c = ta .column (c_repr , device = self .device )
445+
446+ result = c .drop_null ()
447+
448+ self .assertEqual (c_repr [:- 1 ], list (result ))
449+
450+ with self .assertRaisesRegex (
451+ expected_exception = TypeError ,
452+ expected_regex = "how parameter for flat columns not supported" ,
453+ ):
454+ c .drop_null (how = "any" )
455+
456+ def base_test_drop_duplicates (self ):
457+ c_repr = ["test" , "test2" , "test3" , "test" ]
458+ c = ta .column (c_repr , device = self .device )
459+
460+ result = c .drop_duplicates ()
461+
462+ self .assertEqual (c_repr [:- 1 ], list (result ))
463+
464+ # TODO: Add functionality for last
465+ with self .assertRaises (expected_exception = AssertionError ):
466+ c .drop_duplicates (keep = "last" )
467+
468+ with self .assertRaisesRegex (
469+ expected_exception = TypeError ,
470+ expected_regex = "subset parameter for flat columns not supported" ,
471+ ):
472+ c .drop_duplicates (subset = c_repr [:2 ])
473+
474+ def base_test_fill_null (self ):
475+ c_repr = ["0" , "1" , None , "3" , "4" , None ]
476+ expected_fill = "TEST"
477+ expected_repr = ["0" , "1" , expected_fill , "3" , "4" , expected_fill ]
478+ c = ta .column (c_repr , device = self .device )
479+
480+ result = c .fill_null (expected_fill )
481+
482+ self .assertEqual (expected_repr , list (result ))
483+
484+ with self .assertRaisesRegex (
485+ expected_exception = TypeError ,
486+ expected_regex = "fill_null with bytes is not supported" ,
487+ ):
488+ c .fill_null (expected_fill .encode ())
489+
490+ def base_test_isin (self ):
491+ c_repr = [f"test{ x } " for x in range (5 )]
492+ c = ta .column (c_repr , device = self .device )
493+ self .assertTrue (all (c .isin (values = c_repr + ["test_123" ])))
494+ self .assertFalse (any (c .isin (values = ["test5" , "test6" , "test7" ])))
495+
496+ def base_test_bool (self ):
497+ c = ta .column ([f"test{ x } " for x in range (5 )], device = self .device )
498+ with self .assertRaisesRegex (
499+ expected_exception = ValueError ,
500+ expected_regex = r"The truth value of a.*is ambiguous. Use a.any\(\) or a.all\(\)." ,
501+ ):
502+ bool (c )
503+
504+ def base_test_flatmap (self ):
505+ c = ta .column (["test1" , "test2" , None , None , "test3" ], device = self .device )
506+ expected_result = [
507+ "test1" ,
508+ "test1" ,
509+ "test2" ,
510+ "test2" ,
511+ None ,
512+ None ,
513+ None ,
514+ None ,
515+ "test3" ,
516+ "test3" ,
517+ ]
518+ result = c .flatmap (lambda xs : [xs , xs ])
519+ self .assertEqual (expected_result , list (result ))
520+
521+ def base_test_any (self ):
522+ c_some = ta .column (["test1" , "test2" , None , None , "test3" ], device = self .device )
523+ c_none = ta .column ([], dtype = dt .string , device = self .device )
524+ c_none = c_none .append ([None ])
525+ self .assertTrue (c_some .any ())
526+ self .assertFalse (c_none .any ())
527+
528+ def base_test_all (self ):
529+ c_all = ta .column (["test" , "test2" , "test3" ], device = self .device )
530+ c_partial = ta .column (["test" , "test2" , None , None ], device = self .device )
531+ c_none = ta .column ([], dtype = dt .string , device = self .device )
532+ c_none = c_none .append ([None ])
533+ self .assertTrue (c_all .all ())
534+ self .assertTrue (c_partial .all ())
535+ self .assertTrue (c_none .all ())
536+
348537
349538if __name__ == "__main__" :
350539 unittest .main ()
0 commit comments