@@ -494,8 +494,8 @@ class StopTimesTable(DataFrameModel):
494494 nullable = True ,
495495 coerce = True ,
496496 )
497- arrival_time : Series [TimeString ] = Field (nullable = True , coerce = True )
498- departure_time : Series [TimeString ] = Field (nullable = True , coerce = True )
497+ arrival_time : Series [pa . Timestamp ] = Field (nullable = True , default = pd . NaT , coerce = True )
498+ departure_time : Series [pa . Timestamp ] = Field (nullable = True , default = pd . NaT , coerce = True )
499499
500500 # Optional
501501 shape_dist_traveled : Optional [Series [float ]] = Field (coerce = True , nullable = True , ge = 0 )
@@ -516,6 +516,17 @@ class Config:
516516
517517 unique : ClassVar [list [str ]] = ["trip_id" , "stop_sequence" ]
518518
519+ @pa .dataframe_parser
520+ def parse_times (cls , df ):
521+ """Parse time strings to timestamps."""
522+ # Convert string times to timestamps
523+ if "arrival_time" in df .columns and "departure_time" in df .columns :
524+ # Convert string times to timestamps using str_to_time_series
525+ df ["arrival_time" ] = str_to_time_series (df ["arrival_time" ])
526+ df ["departure_time" ] = str_to_time_series (df ["departure_time" ])
527+
528+ return df
529+
519530
520531class WranglerStopTimesTable (StopTimesTable ):
521532 """Wrangler flavor of GTFS StopTimesTable.
@@ -538,8 +549,6 @@ class WranglerStopTimesTable(StopTimesTable):
538549 - 1: No drop off available
539550 - 2: Must phone agency to arrange drop off
540551 - 3: Must coordinate with driver to arrange drop off
541- arrival_time (datetime.datetime): The arrival time in datetime format.
542- departure_time (datetime.datetime): The departure time in datetime format.
543552 shape_dist_traveled (Optional[float]): The shape distance traveled.
544553 timepoint (Optional[TimepointType]): The timepoint type. Values can be:
545554 - 0: The stop is not a timepoint
@@ -548,39 +557,9 @@ class WranglerStopTimesTable(StopTimesTable):
548557 """
549558
550559 stop_id : Series [int ] = Field (nullable = False , coerce = True , description = "The model_node_id." )
551- arrival_time : Series [Timestamp ] = Field (nullable = True , default = pd .NaT , coerce = False )
552- departure_time : Series [Timestamp ] = Field (nullable = True , default = pd .NaT , coerce = False )
553560 projects : Series [str ] = Field (coerce = True , default = "" )
554-
555- @pa .dataframe_parser
556- def parse_times (cls , df ):
557- """Parse arrival and departure times.
558-
559- - Check that all times are timestamps <24h.
560- - Check that arrival_time and departure_time are not both "00:00:00". If so, set
561- them to NaT.
562-
563- """
564- # if arrival_time and departure_time are not set or are both set to "00:00:00", set them to NaT
565- if "arrival_time" not in df .columns :
566- df ["arrival_time" ] = pd .NaT
567- if "departure_time" not in df .columns :
568- df ["departure_time" ] = pd .NaT
569- msg = f"stop_times before parsing: \n { df [['arrival_time' , 'departure_time' ]]} "
570- # WranglerLogger.debug(msg)
571- filler_timestrings = (df ["arrival_time" ] == Timestamp ("00:00:00" )) & (
572- df ["departure_time" ] == Timestamp ("00:00:00" )
573- )
574-
575- df .loc [filler_timestrings , "arrival_time" ] = pd .NaT
576- df .loc [filler_timestrings , "departure_time" ] = pd .NaT
577- msg = f"stop_times after filling with NaT: \n { df [['arrival_time' , 'departure_time' ]]} "
578- # WranglerLogger.debug(msg)
579- df ["arrival_time" ] = str_to_time_series (df ["arrival_time" ])
580- df ["departure_time" ] = str_to_time_series (df ["departure_time" ])
581- msg = f"stop_times after parsing: \n { df [['arrival_time' , 'departure_time' ]]} "
582- # WranglerLogger.debug(msg)
583- return df
561+ arrival_time : Series [pa .Timestamp ] = Field (nullable = True , default = pd .NaT , coerce = True )
562+ departure_time : Series [pa .Timestamp ] = Field (nullable = True , default = pd .NaT , coerce = True )
584563
585564 class Config :
586565 """Config for the StopTimesTable data model."""
@@ -594,3 +573,14 @@ class Config:
594573 }
595574
596575 unique : ClassVar [list [str ]] = ["trip_id" , "stop_sequence" ]
576+
577+ @pa .dataframe_parser
578+ def parse_times (cls , df ):
579+ """Parse time strings to timestamps."""
580+ # Convert string times to timestamps
581+ if "arrival_time" in df .columns and "departure_time" in df .columns :
582+ # Convert string times to timestamps using str_to_time_series
583+ df ["arrival_time" ] = str_to_time_series (df ["arrival_time" ])
584+ df ["departure_time" ] = str_to_time_series (df ["departure_time" ])
585+
586+ return df
0 commit comments