@@ -2802,3 +2802,57 @@ def test_end_to_end_with_constraints():
28022802
28032803 # Assert
28042804 synthesizer .validate (synthetic_data )
2805+
2806+
2807+ def test_datetime_warning_doesnt_repeat ():
2808+ """Test that the datetime warning doesn't repeat GH#2739."""
2809+ # Setup
2810+ composite_data = {
2811+ 'main' : pd .DataFrame ({
2812+ 'pk' : [1 , 2 , 3 , 4 , 5 ],
2813+ 'denormalized_primary_key_1' : [1 , 1 , 2 , 2 , 5 ],
2814+ 'denormalized_primary_key_2' : ['a' , 'a' , 'b' , 'c' , 'c' ],
2815+ 'denormalized_column' : [
2816+ '2020-01-01' ,
2817+ '2020-01-01' ,
2818+ '2020-01-02' ,
2819+ '2020-01-02' ,
2820+ '2020-01-03' ,
2821+ ],
2822+ 'other_col' : ['2020-01-01' , '2020-01-02' , '2020-01-03' , '2020-01-04' , '2020-01-05' ],
2823+ })
2824+ }
2825+
2826+ composite_metadata = Metadata .load_from_dict ({
2827+ 'tables' : {
2828+ 'main' : {
2829+ 'columns' : {
2830+ 'pk' : {'sdtype' : 'id' },
2831+ 'denormalized_primary_key_1' : {'sdtype' : 'id' },
2832+ 'denormalized_primary_key_2' : {'sdtype' : 'categorical' },
2833+ 'denormalized_column' : {'sdtype' : 'datetime' },
2834+ 'other_col' : {'sdtype' : 'datetime' , 'datetime_format' : '%Y-%m-%d' },
2835+ },
2836+ 'primary_key' : 'pk' ,
2837+ },
2838+ },
2839+ })
2840+
2841+ comp_synth = HMASynthesizer (composite_metadata )
2842+
2843+ # Run
2844+ with warnings .catch_warnings (record = True ) as w :
2845+ warnings .simplefilter ('always' )
2846+ comp_synth .fit (composite_data )
2847+ comp_synth .sample (1 )
2848+
2849+ # Assert
2850+ msg = (
2851+ "No 'datetime_format' is present in the metadata for the following columns:\n "
2852+ ' Table Name Column Name sdtype datetime_format\n '
2853+ ' main denormalized_column datetime None\n '
2854+ 'Without this specification, SDV may not be able to accurately parse the data. '
2855+ "We recommend adding datetime formats using 'update_column'."
2856+ )
2857+ matching_warnings = [warning for warning in w if str (warning .message ) == msg ]
2858+ assert len (matching_warnings ) == 1
0 commit comments