本文整理匯總了Python中pandas.Timestamp.now方法的典型用法代碼示例。如果您正苦於以下問題:Python Timestamp.now方法的具體用法?Python Timestamp.now怎麽用?Python Timestamp.now使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.Timestamp
的用法示例。
在下文中一共展示了Timestamp.now方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_now
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_now(self):
# GH#9000
ts_from_string = Timestamp('now')
ts_from_method = Timestamp.now()
ts_datetime = datetime.now()
ts_from_string_tz = Timestamp('now', tz='US/Eastern')
ts_from_method_tz = Timestamp.now(tz='US/Eastern')
# Check that the delta between the times is less than 1s (arbitrarily
# small)
delta = Timedelta(seconds=1)
assert abs(ts_from_method - ts_from_string) < delta
assert abs(ts_datetime - ts_from_method) < delta
assert abs(ts_from_method_tz - ts_from_string_tz) < delta
assert (abs(ts_from_string_tz.tz_localize(None) -
ts_from_method_tz.tz_localize(None)) < delta)
示例2: test_class_ops_pytz
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_class_ops_pytz(self):
def compare(x, y):
assert (int(Timestamp(x).value / 1e9) ==
int(Timestamp(y).value / 1e9))
compare(Timestamp.now(), datetime.now())
compare(Timestamp.now('UTC'), datetime.now(timezone('UTC')))
compare(Timestamp.utcnow(), datetime.utcnow())
compare(Timestamp.today(), datetime.today())
current_time = calendar.timegm(datetime.now().utctimetuple())
compare(Timestamp.utcfromtimestamp(current_time),
datetime.utcfromtimestamp(current_time))
compare(Timestamp.fromtimestamp(current_time),
datetime.fromtimestamp(current_time))
date_component = datetime.utcnow()
time_component = (date_component + timedelta(minutes=10)).time()
compare(Timestamp.combine(date_component, time_component),
datetime.combine(date_component, time_component))
示例3: test_timestamp
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_timestamp(self):
# GH#17329
# tz-naive --> treat it as if it were UTC for purposes of timestamp()
ts = Timestamp.now()
uts = ts.replace(tzinfo=utc)
assert ts.timestamp() == uts.timestamp()
tsc = Timestamp('2014-10-11 11:00:01.12345678', tz='US/Central')
utsc = tsc.tz_convert('UTC')
# utsc is a different representation of the same time
assert tsc.timestamp() == utsc.timestamp()
if PY3:
# datetime.timestamp() converts in the local timezone
with tm.set_timezone('UTC'):
# should agree with datetime.timestamp method
dt = ts.to_pydatetime()
assert dt.timestamp() == ts.timestamp()
示例4: test_class_ops_dateutil
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_class_ops_dateutil(self):
def compare(x, y):
assert (int(np.round(Timestamp(x).value / 1e9)) ==
int(np.round(Timestamp(y).value / 1e9)))
compare(Timestamp.now(), datetime.now())
compare(Timestamp.now('UTC'), datetime.now(tzutc()))
compare(Timestamp.utcnow(), datetime.utcnow())
compare(Timestamp.today(), datetime.today())
current_time = calendar.timegm(datetime.now().utctimetuple())
compare(Timestamp.utcfromtimestamp(current_time),
datetime.utcfromtimestamp(current_time))
compare(Timestamp.fromtimestamp(current_time),
datetime.fromtimestamp(current_time))
date_component = datetime.utcnow()
time_component = (date_component + timedelta(minutes=10)).time()
compare(Timestamp.combine(date_component, time_component),
datetime.combine(date_component, time_component))
示例5: _DWX_MTX_SEND_MARKETDATA_REQUEST_
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def _DWX_MTX_SEND_MARKETDATA_REQUEST_(self,
_symbol='EURUSD',
_timeframe=1,
_start='2019.01.04 17:00:00',
_end=Timestamp.now().strftime('%Y.%m.%d %H:%M:00')):
#_end='2019.01.04 17:05:00'):
_msg = "{};{};{};{};{}".format('DATA',
_symbol,
_timeframe,
_start,
_end)
# Send via PUSH Socket
self.remote_send(self._PUSH_SOCKET, _msg)
##########################################################################
示例6: _DWX_MTX_SEND_MARKETHIST_REQUEST_
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def _DWX_MTX_SEND_MARKETHIST_REQUEST_(self,
_symbol='EURUSD',
_timeframe=1,
_start='2019.01.04 17:00:00',
_end=Timestamp.now().strftime('%Y.%m.%d %H:%M:00')):
#_end='2019.01.04 17:05:00'):
_msg = "{};{};{};{};{}".format('HIST',
_symbol,
_timeframe,
_start,
_end)
# Send via PUSH Socket
self.remote_send(self._PUSH_SOCKET, _msg)
##########################################################################
示例7: get_file_info
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def get_file_info(self):
"""Internal method to get the file information.
Returns
-------
file_info: dict
dictionary with file information.
"""
# Check if file_info already exists
if hasattr(self, "file_info"):
file_info = self.file_info
else:
file_info = {"date_created": Timestamp.now()}
file_info["date_modified"] = Timestamp.now()
file_info["pastas_version"] = __version__
try:
file_info["owner"] = getlogin()
except:
file_info["owner"] = "Unknown"
return file_info
示例8: test_td_sub_mixed_most_timedeltalike_object_dtype_array
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_td_sub_mixed_most_timedeltalike_object_dtype_array(self):
# GH#21980
now = Timestamp.now()
arr = np.array([now,
Timedelta('1D'),
np.timedelta64(2, 'h')])
exp = np.array([now - Timedelta('1D'),
Timedelta('0D'),
np.timedelta64(2, 'h') - Timedelta('1D')])
res = arr - Timedelta('1D')
tm.assert_numpy_array_equal(res, exp)
示例9: test_td_rsub_mixed_most_timedeltalike_object_dtype_array
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_td_rsub_mixed_most_timedeltalike_object_dtype_array(self):
# GH#21980
now = Timestamp.now()
arr = np.array([now,
Timedelta('1D'),
np.timedelta64(2, 'h')])
with pytest.raises(TypeError):
Timedelta('1D') - arr
示例10: test_td_add_mixed_timedeltalike_object_dtype_array
# 需要導入模塊: from pandas import Timestamp [as 別名]
# 或者: from pandas.Timestamp import now [as 別名]
def test_td_add_mixed_timedeltalike_object_dtype_array(self, op):
# GH#21980
now = Timestamp.now()
arr = np.array([now,
Timedelta('1D')])
exp = np.array([now + Timedelta('1D'),
Timedelta('2D')])
res = op(arr, Timedelta('1D'))
tm.assert_numpy_array_equal(res, exp)