Skip to content

Format datetime as UTC #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions api_client/python/timesketch_api_client/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import pandas

from . import error
from . import resource
from . import searchtemplate

from . import error, resource, searchtemplate

logger = logging.getLogger("timesketch_api.search")

Expand Down Expand Up @@ -1129,18 +1126,10 @@ def to_pandas(self):
return_list.append(source)

data_frame = pandas.DataFrame(return_list)
if "datetime" in data_frame:
try:
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime)
except pandas.errors.OutOfBoundsDatetime:
pass
elif "timestamp" in data_frame:
try:
data_frame["datetime"] = pandas.to_datetime(
data_frame.timestamp / 1e6, utc=True, unit="s"
)
except pandas.errors.OutOfBoundsDatetime:
pass
try:
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime, utc=True)
except pandas.errors.OutOfBoundsDatetime:
pass

return data_frame

Expand Down
4 changes: 0 additions & 4 deletions api_client/python/timesketch_api_client/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,6 @@ def explore(
RuntimeError: if the query is missing needed values, or if the
sketch is archived.
"""
logger.warning(
"Using this function is discouraged, please consider using "
"the search.Search object instead, which is more flexible."
)

if not (query_string or query_filter or query_dsl or view):
raise RuntimeError("You need to supply a query or view")
Expand Down
20 changes: 14 additions & 6 deletions api_client/python/timesketch_api_client/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ def json(self):
},
"objects": [
{
"id": 1,
"name": "test",
"searchindex": {"id": 1234, "index_name": "test"},
"_id": 1234,
"_index": "test",
"_source": {
"datetime": "2012-03-14T08:12:03.998281",
"id": 1,
"name": "test",
},
}
],
}
Expand All @@ -228,9 +232,13 @@ def json(self):
},
"objects": [
{
"id": 2,
"name": "more_test",
"searchindex": {"id": 42, "index_name": "even_more_test"},
"_id": 42,
"_index": "even_more_test",
"_source": {
"datetime": "2012-03-14T08:12:03.998281",
"id": 2,
"name": "more_test",
},
}
],
}
Expand Down