@@ -790,6 +790,7 @@ def test_cut_with_nullable_int64():
790
790
791
791
tm .assert_series_equal (result , expected )
792
792
793
+
793
794
def test_datetime_cut_notna ():
794
795
"""
795
796
Ensure pd.cut can handle DatetimeArray without raising an AttributeError
@@ -800,20 +801,22 @@ def test_datetime_cut_notna():
800
801
data = to_datetime (["2023-09-17" , "2023-10-06" ])
801
802
datetime_array = data .array
802
803
803
- bins = pd .date_range (start = "2023-09-16" , periods = 3 , freq = ' 10D' )
804
+ bins = pd .date_range (start = "2023-09-16" , periods = 3 , freq = " 10D" )
804
805
805
806
# Use pd.cut to categorize datetime data and capture the result
806
807
result = pd .cut (datetime_array , bins = bins )
807
808
808
809
expected_intervals = IntervalIndex .from_arrays (
809
- [pd .Timestamp (' 2023-09-16' ), pd .Timestamp (' 2023-09-26' )],
810
- [pd .Timestamp (' 2023-09-26' ), pd .Timestamp (' 2023-10-06' )],
811
- closed = ' right'
810
+ [pd .Timestamp (" 2023-09-16" ), pd .Timestamp (" 2023-09-26" )],
811
+ [pd .Timestamp (" 2023-09-26" ), pd .Timestamp (" 2023-10-06" )],
812
+ closed = " right" ,
812
813
)
813
814
814
815
expected = Series (expected_intervals ).astype (CategoricalDtype (ordered = True ))
815
816
816
817
tm .assert_categorical_equal (result .categories , expected .values )
817
818
818
- assert not hasattr (result , 'notna' ), "AttributeError related to 'notna' should not be present"
819
- assert len (result .categories ) == 2 , "There should be exactly 2 bins"
819
+ assert not hasattr (
820
+ result , "notna"
821
+ ), "AttributeError related to 'notna' should not be present"
822
+ assert len (result .categories ) == 2 , "There should be exactly 2 bins"
0 commit comments