37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试时间戳处理的脚本
|
|
"""
|
|
import pandas as pd
|
|
import numpy as np
|
|
from datetime import datetime
|
|
|
|
def test_timestamp_handling():
|
|
"""测试时间戳处理逻辑"""
|
|
|
|
# 创建测试数据
|
|
dates = pd.date_range('2024-01-01', periods=100, freq='1min')
|
|
df = pd.DataFrame({
|
|
'close': np.random.randn(100),
|
|
'volume': np.random.randn(100)
|
|
}, index=dates)
|
|
|
|
print("测试数据创建成功")
|
|
print(f"数据类型: {type(df.index[0])}")
|
|
print(f"索引示例: {df.index[0]}")
|
|
|
|
# 测试时间戳转换
|
|
for i in range(-10, 0):
|
|
last_idx = df.index[i]
|
|
if isinstance(last_idx, pd.Timestamp):
|
|
ts = last_idx.tz_localize(None) if last_idx.tz else last_idx
|
|
timestamp = int(ts.timestamp())
|
|
print(f"索引 {i}: {last_idx} -> {timestamp}")
|
|
else:
|
|
timestamp = int(last_idx) if isinstance(last_idx, (int, np.integer)) else int(pd.Timestamp.utcnow().timestamp())
|
|
print(f"索引 {i}: {last_idx} -> {timestamp}")
|
|
|
|
print("时间戳处理测试完成")
|
|
|
|
if __name__ == "__main__":
|
|
test_timestamp_handling() |