33
44date_to_str,
55str_to_datetime,
6- to_str ,
7- to_min ,
6+ datetime_to_str ,
7+ datetime_to_min ,
88min_to_datetime,
99to_day_of_week_int,
1010working_day,
@@ -60,15 +60,14 @@ def date_to_str(dt: datetime) -> Text:
6060
6161 Example
6262 -------
63- import datatime
64- time_now = datetime.datetime.now()
65-
63+ >>> import datatime
64+ >>> time_now = datetime.datetime.now()
6665 >>> print(time_now)
67- 2021-04-29 11:01:29.909340
66+ ' 2021-04-29 11:01:29.909340'
6867 >>> print(type(time_now))
69- <class 'datetime.datetime'>
68+ ' <class 'datetime.datetime'>'
7069 >>> print(date_to_str(time_now), type(time_now))
71- 2021-04-29 <class 'str'>
70+ ' 2021-04-29 <class 'str'>'
7271
7372 """
7473 return dt .strftime ('%Y-%m-%d' )
@@ -90,15 +89,14 @@ def str_to_datetime(dt_str: Text) -> datetime:
9089
9190 Example
9291 -------
93- time_1 = '2020-06-29'
94- time_2 = '2020-06-29 12:45:59'
95-
92+ >>> time_1 = '2020-06-29'
93+ >>> time_2 = '2020-06-29 12:45:59'
9694 >>> print(type(time_1), type(time_2))
97- <class 'str'> <class 'str'>
95+ ' <class 'str'> <class 'str'>'
9896 >>> print( str_to_datetime(time_1), type(str_to_datetime(time_1)))
99- 2020-06-29 00:00:00 <class 'datetime.datetime'>
97+ ' 2020-06-29 00:00:00 <class 'datetime.datetime'>'
10098 >>> print(str_to_datetime(time_2), type(str_to_datetime(time_2)))
101- 2020-06-29 12:45:59 <class 'datetime.datetime'>
99+ ' 2020-06-29 12:45:59 <class 'datetime.datetime'>'
102100
103101
104102 """
@@ -124,16 +122,14 @@ def datetime_to_str(dt: datetime) -> Text:
124122
125123 Example:
126124 -------
127- import datetime
128- time_now = datetime.datetime.now()
129-
125+ >>> import datetime
126+ >>> time_now = datetime.datetime.now()
130127 >>> print(time_now)
131- 2021-04-29 14:15:29.708113
128+ ' 2021-04-29 14:15:29.708113'
132129 >>> print(type(time_now))
133- <class 'datetime.datetime'>
134-
135- >>> print(data_to_str(time_now), type(data_to_str(time_now)))
136- 2021-04-29 14:15:29 <class 'str' >
130+ '<class 'datetime.datetime'>'
131+ >>> print(datetime_to_str(time_now), type(datetime_to_str(time_now)))
132+ '2021-04-29 14:15:29 <class 'str' >'
137133
138134 """
139135 return dt .strftime ('%Y-%m-%d %H:%M:%S' )
@@ -157,13 +153,13 @@ def datetime_to_min(dt: datetime) -> int:
157153
158154 Example
159155 -------
160- import datetime
156+ >>> import datetime
161157
162- time_now = datetime.datetime.now()
163- >>> print(type(to_min (time_now)))
164- <class 'int'>
165- >>> to_min (time_now)
166- 26996497
158+ >>> time_now = datetime.datetime.now()
159+ >>> print(type(datetime_to_min (time_now)))
160+ ' <class 'int'>'
161+ >>> datetime_to_min (time_now)
162+ ' 26996497'
167163
168164 """
169165 # get an integer time slot from a datetime
@@ -191,7 +187,7 @@ def min_to_datetime(minutes: int) -> datetime:
191187 Example
192188 -------
193189 >>> print(min_to_datetime(26996497), type(min_to_datetime(26996497)))
194- 2021-04-30 13:37:00 <class 'datetime.datetime'>
190+ ' 2021-04-30 13:37:00 <class 'datetime.datetime'>'
195191
196192 """
197193 return datetime .utcfromtimestamp (minutes * 60 )
@@ -213,15 +209,13 @@ def to_day_of_week_int(dt: datetime) -> int:
213209
214210 Example
215211 -------
216- from pymove.utils.datetime import str_to_datetime
217-
218- monday = str_to_datetime('2021-05-3 12:00:01')
219- friday = str_to_datetime('2021-05-7 12:00:01')
220-
212+ >>> from pymove.utils.datetime import str_to_datetime
213+ >>> monday = str_to_datetime('2021-05-3 12:00:01')
214+ >>> friday = str_to_datetime('2021-05-7 12:00:01')
221215 >>> print(to_day_of_week_int(monday), type(to_day_of_week_int(monday)))
222- 0 <class 'int'>
216+ ' 0 <class 'int'>'
223217 >>> print(to_day_of_week_int(friday), type(to_day_of_week_int(friday)))
224- 4 <class 'int'>
218+ ' 4 <class 'int'>'
225219
226220 """
227221 return dt .weekday ()
@@ -252,21 +246,17 @@ def working_day(
252246
253247 Examples
254248 --------
255- from pymove.utils.datetime import str_to_datetime
256-
257- independence_day = str_to_datetime('2021-09-7 12:00:01')
258- # In Brazil this day is a holiday
259- next_day = str_to_datetime('2021-09-8 12:00:01')
260- # In Brazil this day is a Wednesday and isn't a holiday
261-
249+ >>> from pymove.utils.datetime import str_to_datetime
250+ >>> independence_day = str_to_datetime('2021-09-7 12:00:01') # In Brazil this day is a holiday
251+ >>> next_day = str_to_datetime('2021-09-8 12:00:01') # In Brazil this day is a Wednesday and isn't a holiday
262252 >>> print(working_day(independence_day, 'BR'))
263253 False
264254 >>> print(type(working_day(independence_day, 'BR')))
265255 <class 'bool'>
266256 >>> print(working_day(next_day, 'BR'))
267257 True
268258 >>> print(type(working_day(next_day, 'BR')))
269- <class 'bool'>
259+ ' <class 'bool'>'
270260
271261 References
272262 ----------
@@ -302,9 +292,8 @@ def now_str() -> Text:
302292
303293 Examples
304294 --------
305- >>> from pymove import datetime
306- >>> datetime.now_str()
307- "2019-09-02 13:54:16"
295+ >>> now_str()
296+ '2019-09-02 13:54:16'
308297
309298 """
310299 return datetime_to_str (datetime .now ())
@@ -326,9 +315,8 @@ def deltatime_str(deltatime_seconds: float) -> Text:
326315
327316 Examples
328317 --------
329- >>> from pymove import datetime
330- >>> datetime.deltatime_str(1082.7180936336517)
331- "18m:02.718s"
318+ >>> deltatime_str(1082.7180936336517)
319+ '18m:02.718s'
332320
333321 Notes
334322 -----
@@ -362,8 +350,7 @@ def timestamp_to_millis(timestamp: Text) -> int:
362350
363351 Examples
364352 --------
365- >>> from pymove.utils.utils import datetime
366- >>> datetime.timestamp_to_millis("2015-12-12 08:00:00.123000")
353+ >>> timestamp_to_millis('2015-12-12 08:00:00.123000')
367354 1449907200123 (UTC)
368355
369356 """
@@ -386,9 +373,8 @@ def millis_to_timestamp(milliseconds: float) -> Timestamp:
386373
387374 Examples
388375 --------
389- >>> from pymove.utils.utils import datetime
390- >>> datetime.millis_to_timestamp(1449907200123)
391- "2015-12-12 08:00:00.123000"
376+ >>> millis_to_timestamp(1449907200123)
377+ '2015-12-12 08:00:00.123000'
392378
393379 """
394380 return Timestamp (milliseconds , unit = 'ms' )
@@ -410,9 +396,8 @@ def time_to_str(time: Timestamp) -> Text:
410396
411397 Examples
412398 --------
413- >>> from pymove.utils.utils import datetime
414- >>> datetime.time_to_str("2015-12-12 08:00:00.123000")
415- "08:00:00"
399+ >>> time_to_str("2015-12-12 08:00:00.123000")
400+ '08:00:00'
416401
417402 """
418403 return time .strftime ('%H:%M:%S' )
@@ -434,8 +419,7 @@ def str_to_time(dt_str: Text) -> datetime:
434419
435420 Examples
436421 --------
437- >>> from pymove.utils.utils import datetime
438- >>> datetime.str_to_time("08:00:00")
422+ >>> str_to_time("08:00:00")
439423 datetime(1900, 1, 1, 8, 0)
440424
441425 """
@@ -459,12 +443,10 @@ def elapsed_time_dt(start_time: datetime) -> int:
459443
460444 Examples
461445 --------
462- from datetime import datetime
463- from pymove.utils.datetime import str_to_datetime
464-
465- start_time_1 = datetime(2020, 6, 29, 0, 0)
466- start_time_2 = str_to_datetime('2020-06-29 12:45:59')
467-
446+ >>> from datetime import datetime
447+ >>> from pymove.utils.datetime import str_to_datetime
448+ >>> start_time_1 = datetime(2020, 6, 29, 0, 0)
449+ >>> start_time_2 = str_to_datetime('2020-06-29 12:45:59')
468450 >>> print(elapsed_time_dt(start_time_1))
469451 26411808666
470452 >>> print(elapsed_time_dt(start_time_2))
@@ -492,13 +474,11 @@ def diff_time(start_time: datetime, end_time: datetime) -> int:
492474
493475 Examples
494476 --------
495- from datetime import datetime
496- from pymove.utils.datetime import str_to_datetime
497-
498- time_now = datetime.now()
499- start_time_1 = datetime(2020, 6, 29, 0, 0)
500- start_time_2 = str_to_datetime('2020-06-29 12:45:59')
501-
477+ >>> from datetime import datetime
478+ >>> from pymove.utils.datetime import str_to_datetime
479+ >>> time_now = datetime.now()
480+ >>> start_time_1 = datetime(2020, 6, 29, 0, 0)
481+ >>> start_time_2 = str_to_datetime('2020-06-29 12:45:59')
502482 >>> print(diff_time(start_time_1, time_now))
503483 26411808665
504484 >>> print(diff_time(start_time_2, time_now))
@@ -541,20 +521,19 @@ def create_time_slot_in_minute(
541521
542522 Examples
543523 --------
544- from pymove import datetime
524+ >>> from pymove import datetime
545525 >>> data
546- lat lon datetime id
547- 0 39.984094 116.319236 2008-10-23 05:44:05 1
548- 1 39.984198 116.319322 2008-10-23 05:56:06 1
549- 2 39.984224 116.319402 2008-10-23 05:56:11 1
550- 3 39.984224 116.319402 2008-10-23 06:10:15 1
551-
526+ ' lat lon datetime id'
527+ '0 39.984094 116.319236 2008-10-23 05:44:05 1'
528+ '1 39.984198 116.319322 2008-10-23 05:56:06 1'
529+ '2 39.984224 116.319402 2008-10-23 05:56:11 1'
530+ '3 39.984224 116.319402 2008-10-23 06:10:15 1'
552531 >>> datetime.create_time_slot_in_minute(data, inplace=False)
553- lat lon datetime id time_slot
554- 0 39.984094 116.319236 2008-10-23 05:44:05 1 22
555- 1 39.984198 116.319322 2008-10-23 05:56:06 1 23
556- 2 39.984224 116.319402 2008-10-23 05:56:11 1 23
557- 3 39.984224 116.319402 2008-10-23 06:10:15 1 24
532+ ' lat lon datetime id time_slot'
533+ ' 0 39.984094 116.319236 2008-10-23 05:44:05 1 22'
534+ ' 1 39.984198 116.319322 2008-10-23 05:56:06 1 23'
535+ ' 2 39.984224 116.319402 2008-10-23 05:56:11 1 23'
536+ ' 3 39.984224 116.319402 2008-10-23 06:10:15 1 24'
558537
559538 """
560539 if data .dtypes [label_datetime ] != 'datetime64[ns]' :
@@ -592,18 +571,18 @@ def generate_time_statistics(
592571 Example
593572 -------
594573 >>> df
595- local_label prev_local time_to_prev id
596- 0 house None NaN 1
597- 1 market house 720.0 1
598- 2 market market 5.0 1
599- 3 market market 1.0 1
600- 4 school market 844.0 1
574+ ' local_label prev_local time_to_prev id'
575+ '0 house NaN NaN 1'
576+ '1 market house 720.0 1'
577+ '2 market market 5.0 1'
578+ '3 market market 1.0 1'
579+ '4 school market 844.0 1'
601580
602581 >>> generate_time_statistics(df)
603- local_label prev_local mean std min max sum count
604- 0 house market 844.0 0.000000 844.0 844.0 844.0 1
605- 1 market house 720.0 0.000000 720.0 720.0 720.0 1
606- 2 market market 3.0 2.828427 1.0 5.0 6.0 2
582+ ' local_label prev_local mean std min max sum count'
583+ '0 house market 844.0 0.000000 844.0 844.0 844.0 1'
584+ '1 market house 720.0 0.000000 720.0 720.0 720.0 1'
585+ '2 market market 3.0 2.828427 1.0 5.0 6.0 2'
607586 """
608587 df_statistics = data .groupby (
609588 [local_label , PREV_LOCAL ]
@@ -683,33 +662,28 @@ def threshold_time_statistics(
683662
684663 Example
685664 -------
686- from pymove.utils.datetime import generate_time_statistics, _calc_time_threshold
665+ >>> from pymove.utils.datetime import generate_time_statistics
687666
688667 >>> df
689- local_label prev_local time_to_prev id
690- 0 house None NaN 1
691- 1 market house 720.0 1
692- 2 market market 5.0 1
693- 3 market market 1.0 1
694- 4 school market 844.0 1
668+ ' local_label prev_local time_to_prev id'
669+ '0 house NaN NaN 1'
670+ '1 market house 720.0 1'
671+ '2 market market 5.0 1'
672+ '3 market market 1.0 1'
673+ '4 school market 844.0 1'
695674
696675 >>> statistics = generate_time_statistics(df)
697676 >>> statistics
698- local_label prev_local mean std min max sum count
699- 0 house market 844.0 0.000000 844.0 844.0 844.0 1
700- 1 market house 720.0 0.000000 720.0 720.0 720.0 1
701- 2 market market 3.0 2.828427 1.0 5.0 6.0 2
702-
677+ ' local_label prev_local mean std min max sum count'
678+ '0 house market 844.0 0.000000 844.0 844.0 844.0 1'
679+ '1 market house 720.0 0.000000 720.0 720.0 720.0 1'
680+ '2 market market 3.0 2.828427 1.0 5.0 6.0 2'
703681 >>> threshold_time_statistics(statistics)
704- local_label prev_local mean std min max sum count
705- 0 house market 844.0 0.000000 844.0 844.0 844.0 1
706- 1 market house 720.0 0.000000 720.0 720.0 720.0 1
707- 2 market market 3.0 2.828427 1.0 5.0 6.0 2
708-
709- threshold
710- 0 844.0
711- 1 720.0
712- 2 5.8
682+ ' local_label prev_local mean std min max sum count threshold'
683+ '0 house market 844.0 0.000000 844.0 844.0 844.0 1 844.0'
684+ '1 market house 720.0 0.000000 720.0 720.0 720.0 1 720.0'
685+ '2 market market 3.0 2.828427 1.0 5.0 6.0 2 5.8'
686+
713687 """
714688 if not inplace :
715689 df_statistics = df_statistics .copy ()
0 commit comments