10
10
from pytest import param
11
11
12
12
import ibis
13
+ import ibis .common .exceptions as com
13
14
import ibis .expr .datatypes as dt
14
15
from ibis .backends .pandas .execution .temporal import day_name
15
16
@@ -563,7 +564,7 @@ def test_strftime(backend, alltypes, df, expr_fn, pandas_pattern):
563
564
],
564
565
)
565
566
@pytest .mark .notimpl (["datafusion" , "mysql" , "postgres" , "sqlite" ])
566
- def test_to_timestamp (backend , con , unit ):
567
+ def test_integer_to_timestamp (backend , con , unit ):
567
568
backend_unit = backend .returned_timestamp_unit
568
569
factor = unit_factors [unit ]
569
570
@@ -579,6 +580,75 @@ def test_to_timestamp(backend, con, unit):
579
580
assert result == expected
580
581
581
582
583
+ @pytest .mark .parametrize (
584
+ 'fmt, timezone' ,
585
+ [
586
+ # "11/01/10" - "month/day/year"
587
+ param (
588
+ '%m/%d/%y' ,
589
+ "UTC" ,
590
+ id = "mysql_format" ,
591
+ marks = pytest .mark .never (
592
+ ["pyspark" ], reason = "datetime formatting style not supported"
593
+ ),
594
+ ),
595
+ param (
596
+ 'MM/dd/yy' ,
597
+ "UTC" ,
598
+ id = "pyspark_format" ,
599
+ marks = pytest .mark .never (
600
+ ["mysql" ], reason = "datetime formatting style not supported"
601
+ ),
602
+ ),
603
+ ],
604
+ )
605
+ @pytest .mark .notimpl (
606
+ [
607
+ 'dask' ,
608
+ 'pandas' ,
609
+ 'postgres' ,
610
+ 'duckdb' ,
611
+ 'clickhouse' ,
612
+ 'sqlite' ,
613
+ 'impala' ,
614
+ 'datafusion' ,
615
+ ]
616
+ )
617
+ def test_string_to_timestamp (backend , con , fmt , timezone ):
618
+ table = con .table ('functional_alltypes' )
619
+ result = table .mutate (
620
+ date = table .date_string_col .to_timestamp (fmt , timezone )
621
+ ).execute ()
622
+
623
+ # TEST: do we get the same date out, that we put in?
624
+ # format string assumes that we are using pandas' strftime
625
+ for i , val in enumerate (result ["date" ]):
626
+ assert val .strftime ("%m/%d/%y" ) == result ["date_string_col" ][i ]
627
+
628
+
629
+ @pytest .mark .notimpl (
630
+ [
631
+ 'dask' ,
632
+ 'pandas' ,
633
+ 'postgres' ,
634
+ 'duckdb' ,
635
+ 'clickhouse' ,
636
+ 'sqlite' ,
637
+ 'impala' ,
638
+ 'datafusion' ,
639
+ ]
640
+ )
641
+ def test_string_to_timestamp_tz_error (backend , con ):
642
+ table = con .table ('functional_alltypes' )
643
+
644
+ with pytest .raises (com .UnsupportedArgumentError ):
645
+ table .mutate (
646
+ date = table .date_string_col .to_timestamp (
647
+ "%m/%d/%y" , 'non-utc-timezone'
648
+ )
649
+ ).compile ()
650
+
651
+
582
652
@pytest .mark .parametrize (
583
653
('date' , 'expected_index' , 'expected_day' ),
584
654
[
0 commit comments