#!/usr/bin/python3
import numpy as np
import pandas as pd
import time

# numpy astype test
try:
    print(np.array([12.7,-435,np.nan]).astype('i8'))
except Exception as e:
    print(e)

# near-limits test
timestamp_overflow_years=2**63/(1e9*60*60*24*365.2425)
for a in [timestamp_overflow_years+0.1,timestamp_overflow_years-0.1,-timestamp_overflow_years+0.1,-timestamp_overflow_years-0.1]:
    try:
        print(a,pd.to_datetime(pd.Series([0,1,a],dtype=float),unit="Y",errors='raise'))
    except Exception as e:
        print(a,e)

# speed test, one long
try:
    a=pd.Series(1e8*np.random.randn(1000000))
    t=time.time()
    b=pd.to_datetime(a,unit="s",errors='raise')
    print(time.time()-t)
except Exception as e:
    print(e)

# speed test, many short
try:
    a=pd.DataFrame(1e8*np.random.randn(10,1000))
    t=time.time()
    for n in range(1000):
        b=pd.to_datetime(a[n],unit="s",errors='raise')
    print(time.time()-t)
except Exception as e:
    print(e)
