Skip to content

Commit 8d1b4ce

Browse files
committed
fix some indentation
2 parents 74b63ae + 65f6ce4 commit 8d1b4ce

File tree

1 file changed

+59
-66
lines changed

1 file changed

+59
-66
lines changed

pymove/utils/trajectories.py

Lines changed: 59 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ def read_csv(
7373
Examples
7474
--------
7575
>>> from pymove.utils.trajectories import read_csv
76-
>>> move_df = read_csv('...geolife_sample.csv')
76+
>>> move_df = read_csv('geolife_sample.csv')
7777
>>> move_df.head()
78-
lat lon datetime id
79-
0 39.984094 116.319236 2008-10-23 05:53:05 1
80-
1 39.984198 116.319322 2008-10-23 05:53:06 1
81-
2 39.984224 116.319402 2008-10-23 05:53:11 1
82-
3 39.984211 116.319389 2008-10-23 05:53:16 1
83-
4 39.984217 116.319422 2008-10-23 05:53:21 1
78+
lat lon datetime id
79+
0 39.984094 116.319236 2008-10-23 05:53:05 1
80+
1 39.984198 116.319322 2008-10-23 05:53:06 1
81+
2 39.984224 116.319402 2008-10-23 05:53:11 1
82+
3 39.984211 116.319389 2008-10-23 05:53:16 1
83+
4 39.984217 116.319422 2008-10-23 05:53:21 1
84+
>>> type(move_df)
85+
<class 'pymove.core.pandas.PandasMoveDataFrame'>
8486
"""
8587
data = _read_csv(
8688
filepath_or_buffer,
@@ -109,9 +111,9 @@ def invert_dict(d: Dict) -> Dict:
109111
Examples
110112
--------
111113
>>> from pymove.utils.trajectories import invert_dict
112-
>>> traj_dict = {'lat':39.984094, 'lon':116.319236}
114+
>>> traj_dict = {'a': 1, 'b': 2}
113115
>>> invert_dict(traj_dict)
114-
{39.984094: 'lat', 116.319236: 'lon'} <class 'dict'>
116+
{1: 'a, 2: 'b'}
115117
"""
116118
return {v: k for k, v in d.items()}
117119

@@ -143,9 +145,9 @@ def flatten_dict(
143145
Examples
144146
--------
145147
>>> from pymove.utils.trajectories import flatten_dict
146-
>>> traj_dict = {'lat':39.984094, 'lon':116.319236}
147-
>>> flatten_dict(traj_dict, 'x')
148-
{'x_lat': 39.984094, 'x_lon': 116.319236} <class 'dict'>
148+
>>> d = {'a': 1, 'b': {'c': 2, 'd': 3}}
149+
>>> flatten_dict(d)
150+
{'a': 1, 'b_c': 2, 'b_d': 3}
149151
"""
150152
if not isinstance(d, dict):
151153
return {parent_key: d}
@@ -183,26 +185,25 @@ def flatten_columns(data: DataFrame, columns: List) -> DataFrame:
183185
--------
184186
>>> from pymove.utils.trajectories import flatten_columns
185187
>>> move_df
186-
lat lon datetime id dict_column
187-
0 39.984094 116.319236 2008-10-23 05:53:05 1 {'a': 1}
188-
1 39.984198 116.319322 2008-10-23 05:53:06 1 {'b': 2}
189-
2 39.984224 116.319402 2008-10-23 05:53:11 1 {'c': 3}
190-
3 39.984211 116.319389 2008-10-23 05:53:16 1 {'d': 4}
191-
4 39.984217 116.319422 2008-10-23 05:53:21 1 {'e': 5}
192-
>>> flatten_columns(moveDf, columns = 'dict_column')
193-
lat lon datetime id
194-
0 39.984094 116.319236 2008-10-23 05:53:05 1
195-
1 39.984198 116.319322 2008-10-23 05:53:06 1
196-
2 39.984224 116.319402 2008-10-23 05:53:11 1
197-
3 39.984211 116.319389 2008-10-23 05:53:16 1
198-
4 39.984217 116.319422 2008-10-23 05:53:21 1
199-
200-
dict_column_b dict_column_d dict_column_e dict_column_a dict_column_c
201-
0 NaN NaN NaN 1.0 NaN
202-
1 2.0 NaN NaN NaN NaN
203-
2 NaN NaN NaN NaN 3.0
204-
3 NaN 4.0 NaN NaN NaN
205-
4 NaN NaN 5.0 NaN NaN
188+
lat lon datetime id dict_column
189+
0 39.984094 116.319236 2008-10-23 05:53:05 1 {'a': 1}
190+
1 39.984198 116.319322 2008-10-23 05:53:06 1 {'b': 2}
191+
2 39.984224 116.319402 2008-10-23 05:53:11 1 {'c': 3, 'a': 4}
192+
3 39.984211 116.319389 2008-10-23 05:53:16 1 {'b': 2}
193+
4 39.984217 116.319422 2008-10-23 05:53:21 1 {'a': 3, 'c': 2}
194+
>>> flatten_columns(move_df, columns='dict_column')
195+
lat lon datetime id \
196+
dict_column_b dict_column_c dict_column_a
197+
0 39.984094 116.319236 2008-10-23 05:53:05 1 \
198+
NaN NaN 1.0
199+
1 39.984198 116.319322 2008-10-23 05:53:06 1 \
200+
2.0 NaN NaN
201+
2 39.984224 116.319402 2008-10-23 05:53:11 1 \
202+
NaN 3.0 4.0
203+
3 39.984211 116.319389 2008-10-23 05:53:16 1 \
204+
2.0 NaN NaN
205+
4 39.984217 116.319422 2008-10-23 05:53:21 1 \
206+
NaN 2.0 3.0
206207
"""
207208
data = data.copy()
208209
if not isinstance(columns, list):
@@ -254,13 +255,13 @@ def shift(
254255
Examples
255256
--------
256257
>>> from pymove.utils.trajectories import shift
257-
>>> array = [1,2,3,4,5,6,7]
258-
>>> print(shift(array, 1), type(shift(array, 1)))
259-
[0 1 2 3 4 5 6] <class 'numpy.ndarray'>
260-
>>> print(shift(array, 2), type(shift(array, 2)))
261-
[0 0 1 2 3 4 5] <class 'numpy.ndarray'>
262-
>>> print(shift(array, 3), type(shift(array, 3)))
263-
[0 0 0 1 2 3 4] <class 'numpy.ndarray'>
258+
>>> array = [1, 2, 3, 4, 5, 6, 7]
259+
>>> shift(array, 1)
260+
[0 1 2 3 4 5 6]
261+
>>> shift(array, 0)
262+
[1, 2, 3, 4, 5, 6, 7]
263+
>>> shift(array, -1)
264+
[2 3 4 5 6 7 0]
264265
"""
265266
result = np.empty_like(arr)
266267
if fill_value is None:
@@ -297,18 +298,13 @@ def fill_list_with_new_values(original_list: List, new_list_values: List):
297298
new_list_values : list.
298299
The list from which elements will be copied
299300
300-
Returns
301-
-------
302-
The original list with the content of a secondary list
303-
304301
Example
305302
-------
306303
>>> from pymove.utils.trajectories import fill_list_with_new_values
307-
>>> original_list = [4,3,2,1,0]
308-
>>> new_list = [9,8,7,6,5]
309-
>>> fill_list_with_new_values(original_list, new_list)
310-
>>> print(original_list, type(original_list))
311-
['oveD'] <class 'numpy.ndarray'>[9, 8, 7, 6, 5] <class 'list'>
304+
>>> lst = [1, 2, 3, 4]
305+
>>> fill_list_with_new_values(lt, ['a','b'])
306+
>>> print(lst)
307+
['a', 'b', 3, 4]
312308
"""
313309
n = len(new_list_values)
314310
original_list[:n] = new_list_values
@@ -331,12 +327,9 @@ def object_for_array(object_: Text) -> ndarray:
331327
Examples
332328
--------
333329
>>> from pymove.utils.trajectories import object_for_array
334-
>>> print(object_for_array('lat'), type(object_for_array('lat')))
335-
['a'] <class 'numpy.ndarray'>
336-
>>> print(object_for_array('move'), type(object_for_array('move')))
337-
['ov'] <class 'numpy.ndarray'>
338-
>>> print(object_for_array('moveDf'), type(object_for_array('moveDf')))
339-
['oveD'] <class 'numpy.ndarray'>
330+
>>> list_str = '[1,2,3,4,5]'
331+
>>> object_for_array(list_str)
332+
array([1., 2., 3., 4., 5.], dtype=float32)
340333
"""
341334
if object_ is None:
342335
return object_
@@ -364,25 +357,25 @@ def column_to_array(data: DataFrame, column: Text) -> DataFrame:
364357
Returns
365358
-------
366359
dataframe
367-
Dataframe with the new column...
360+
Dataframe with the selected column converted to list
368361
369362
Example
370363
-------
371364
>>> from pymove.utils.trajectories import column_to_array
372365
>>> move_df
373-
lat lon datetime id list_column
374-
0 39.984094 116.319236 2008-10-23 05:53:05 1 [1,2]
375-
1 39.984198 116.319322 2008-10-23 05:53:06 1 [3,4]
376-
2 39.984224 116.319402 2008-10-23 05:53:11 1 [5,6]
377-
3 39.984211 116.319389 2008-10-23 05:53:16 1 [7,8]
378-
4 39.984217 116.319422 2008-10-23 05:53:21 1 [9,10]
379-
>>> column_to_array(moveDf, column = 'list_column')
366+
lat lon datetime id list_column
367+
0 39.984094 116.319236 2008-10-23 05:53:05 1 '[1,2]'
368+
1 39.984198 116.319322 2008-10-23 05:53:06 1 '[3,4]'
369+
2 39.984224 116.319402 2008-10-23 05:53:11 1 '[5,6]'
370+
3 39.984211 116.319389 2008-10-23 05:53:16 1 '[7,8]'
371+
4 39.984217 116.319422 2008-10-23 05:53:21 1 '[9,10]'
372+
>>> column_to_array(move_df, column='list_column')
380373
lat lon datetime id list_column
381374
0 39.984094 116.319236 2008-10-23 05:53:05 1 [1.0,2.0]
382-
1 39.984198 116.319322 2008-10-23 05:53:06 1 [3.0,4.0]
383-
2 39.984224 116.319402 2008-10-23 05:53:11 1 [5.0,6.0]
384-
3 39.984211 116.319389 2008-10-23 05:53:16 1 [7.0,8.0]
385-
4 39.984217 116.319422 2008-10-23 05:53:21 1 [9.0,10.0]
375+
1 39.984198 116.319322 2008-10-23 05:53:06 1 [3.0,4.0]
376+
2 39.984224 116.319402 2008-10-23 05:53:11 1 [5.0,6.0]
377+
3 39.984211 116.319389 2008-10-23 05:53:16 1 [7.0,8.0]
378+
4 39.984217 116.319422 2008-10-23 05:53:21 1 [9.0,10.0]
386379
"""
387380
data = data.copy()
388381
if column not in data:

0 commit comments

Comments
 (0)