Skip to content

Commit 03b5bb3

Browse files
committed
Format datetime as UTC (#44)
IR-774
1 parent f07e0c5 commit 03b5bb3

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

api_client/python/timesketch_api_client/search.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
import pandas
2121

22-
from . import error
23-
from . import resource
24-
from . import searchtemplate
25-
22+
from . import error, resource, searchtemplate
2623

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

@@ -1141,18 +1138,10 @@ def to_pandas(self):
11411138
return_list.append(source)
11421139

11431140
data_frame = pandas.DataFrame(return_list)
1144-
if "datetime" in data_frame:
1145-
try:
1146-
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime)
1147-
except pandas.errors.OutOfBoundsDatetime:
1148-
pass
1149-
elif "timestamp" in data_frame:
1150-
try:
1151-
data_frame["datetime"] = pandas.to_datetime(
1152-
data_frame.timestamp / 1e6, utc=True, unit="s"
1153-
)
1154-
except pandas.errors.OutOfBoundsDatetime:
1155-
pass
1141+
try:
1142+
data_frame["datetime"] = pandas.to_datetime(data_frame.datetime, utc=True)
1143+
except pandas.errors.OutOfBoundsDatetime:
1144+
pass
11561145

11571146
return data_frame
11581147

api_client/python/timesketch_api_client/sketch.py

-4
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,6 @@ def explore(
10341034
RuntimeError: if the query is missing needed values, or if the
10351035
sketch is archived.
10361036
"""
1037-
logger.warning(
1038-
"Using this function is discouraged, please consider using "
1039-
"the search.Search object instead, which is more flexible."
1040-
)
10411037

10421038
if not (query_string or query_filter or query_dsl or view):
10431039
raise RuntimeError("You need to supply a query or view")

api_client/python/timesketch_api_client/test_lib.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,13 @@ def json(self):
216216
},
217217
"objects": [
218218
{
219-
"id": 1,
220-
"name": "test",
221-
"searchindex": {"id": 1234, "index_name": "test"},
219+
"_id": 1234,
220+
"_index": "test",
221+
"_source": {
222+
"datetime": "2012-03-14T08:12:03.998281",
223+
"id": 1,
224+
"name": "test",
225+
},
222226
}
223227
],
224228
}
@@ -229,9 +233,13 @@ def json(self):
229233
},
230234
"objects": [
231235
{
232-
"id": 2,
233-
"name": "more_test",
234-
"searchindex": {"id": 42, "index_name": "even_more_test"},
236+
"_id": 42,
237+
"_index": "even_more_test",
238+
"_source": {
239+
"datetime": "2012-03-14T08:12:03.998281",
240+
"id": 2,
241+
"name": "more_test",
242+
},
235243
}
236244
],
237245
}

0 commit comments

Comments
 (0)