Skip to content

Commit fe8e312

Browse files
author
pedroccufc
committed
adding examples and updating functions
1 parent f5d55ef commit fe8e312

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

pymove/tests/test_utils_data_augmentation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import pandas as pd
32
from numpy.testing import assert_array_almost_equal
43
from pandas.testing import assert_frame_equal
@@ -19,9 +18,9 @@
1918
from pymove.utils.data_augmentation import (
2019
_augmentation,
2120
append_row,
21+
flatten_trajectories_dataframe,
2222
generate_trajectories_df,
2323
get_all_paths,
24-
flatten_trajectories_dataframe,
2524
instance_crossover_augmentation,
2625
sliding_window,
2726
split_crossover,
@@ -342,4 +341,4 @@ def test_transition_graph_augmentation_all_vertex():
342341
})
343342

344343
transition_graph_augmentation_all_vertex(traj_df)
345-
assert_frame_equal(traj_df, expected)
344+
assert_frame_equal(traj_df, expected)

pymove/tests/test_utils_networkx.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,24 @@
6262

6363
def _transition_graph():
6464
expected_graph = DiGraph()
65-
expected_graph.add_node('85', coords=(-3.8347478, -38.592189),
65+
expected_graph.add_node('85', coords=(-3.8347478, -38.592189),
6666
datetime=['2017-09-02 22:00:27'], freq_source=1, freq_target=0)
67-
expected_graph.add_node('673', coords=(-3.8235834, -38.590389),
67+
expected_graph.add_node('673', coords=(-3.8235834, -38.590389),
6868
datetime=['2017-09-02 22:01:36'], freq_source=0, freq_target=0)
69-
expected_graph.add_node('394', coords=(-3.813889, -38.5904445),
69+
expected_graph.add_node('394', coords=(-3.813889, -38.5904445),
7070
datetime=['2017-09-02 22:03:08'], freq_source=0, freq_target=0)
71-
expected_graph.add_node('263', coords=(-3.9067654, -38.5907723),
71+
expected_graph.add_node('263', coords=(-3.9067654, -38.5907723),
7272
datetime=['2017-09-02 22:03:46'], freq_source=0, freq_target=0)
73-
expected_graph.add_node('224', coords=(-3.8857223, -38.5928892),
73+
expected_graph.add_node('224', coords=(-3.8857223, -38.5928892),
7474
datetime=['2017-09-02 22:07:19'], freq_source=0, freq_target=0)
75-
expected_graph.add_node('623', coords=(-3.8828723, -38.5929789),
75+
expected_graph.add_node('623', coords=(-3.8828723, -38.5929789),
7676
datetime=['2017-09-02 22:07:40'], freq_source=0, freq_target=1)
7777
expected_graph.add_edge( '85', '673', weight=1, mean_times='0 days 00:01:09')
7878
expected_graph.add_edge('673', '394', weight=1, mean_times='0 days 00:01:32')
7979
expected_graph.add_edge('394', '263', weight=1, mean_times='0 days 00:00:38')
8080
expected_graph.add_edge('263', '224', weight=1, mean_times='0 days 00:03:33')
8181
expected_graph.add_edge('224', '623', weight=1, mean_times='0 days 00:00:21')
82-
82+
8383
return expected_graph
8484

8585

@@ -225,4 +225,4 @@ def test_read_graph_json(tmpdir):
225225

226226
saved_graph = read_graph_json(filename_write_default)
227227

228-
assert_equal(saved_graph, expected)
228+
assert_equal(saved_graph, expected)

pymove/tests/test_utils_trajectories.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
)
2222
from pymove.utils.networkx import build_transition_graph_from_df
2323
from pymove.utils.trajectories import (
24-
append_trajectory,
25-
split_trajectory,
24+
append_trajectory,
25+
columns_to_array,
2626
object_for_array,
27-
columns_to_array
27+
split_trajectory,
2828
)
2929

3030
list_data = [
@@ -59,7 +59,7 @@
5959
pd.Timestamp('2017-09-02 22:03:08')],
6060
[pd.Timestamp('2017-09-02 23:03:46'),
6161
pd.Timestamp('2017-09-02 23:07:19'),
62-
pd.Timestamp('2017-09-02 23:07:40'),
62+
pd.Timestamp('2017-09-02 23:07:40'),
6363
pd.Timestamp('2017-09-02 23:09:10')]],
6464
LOCAL_LABEL: [[85, 673, 394], [263, 224, 623, 394]],
6565
LATITUDE: [[-3.8347478, -3.8235834, -3.813889],
@@ -264,4 +264,4 @@ def test_columns_to_array():
264264
})
265265

266266
columns_to_array(df)
267-
assert_frame_equal(df, expected)
267+
assert_frame_equal(df, expected)

pymove/utils/trajectories.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
from __future__ import annotations
1717

18+
from ast import literal_eval
1819
from itertools import chain
1920
from typing import Any, Generator, Text
2021

@@ -27,16 +28,15 @@
2728
from pandas._typing import FilePathOrBuffer
2829

2930
from pymove.core.dataframe import MoveDataFrame
30-
from pymove.utils.networkx import graph_to_dict
3131
from pymove.utils.constants import (
3232
DATETIME,
3333
LATITUDE,
3434
LOCAL_LABEL,
3535
LONGITUDE,
36-
TID_STAT,
3736
TRAJ_ID,
3837
TYPE_PANDAS,
3938
)
39+
from pymove.utils.networkx import graph_to_dict
4040

4141

4242
def read_csv(
@@ -484,19 +484,19 @@ def object_for_array(object_: str) -> ndarray:
484484
>>> from pymove.utils.trajectories import object_for_array
485485
>>>
486486
>>> object_1, object_2, object_3
487-
('[1, 2, 3]', '[1.5, 2.5, 3.5]', '[event, event]')
487+
('[1, 2, 3]', '[1.5, 2.5, 3.5]', "['event', 'event']")
488488
>>>
489489
>>> object_for_array(object_1)
490490
[1, 2, 3]
491491
>>> object_for_array(object_2)
492492
[1.5, 2.5, 3.5]
493493
>>> object_for_array(object_3)
494-
[event, event]
494+
['event', 'event' ]
495495
"""
496496
if object_ is None:
497497
return object_
498498

499-
return eval('[' + object_ + ']', {'nan': np.nan})[0]
499+
return literal_eval('[' + object_ + ']')[0]
500500

501501

502502
def columns_to_array(

0 commit comments

Comments
 (0)