Skip to content

Commit

Permalink
chore: run black and clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Borketh committed Aug 24, 2024
1 parent 536a290 commit 60a2d62
Show file tree
Hide file tree
Showing 29 changed files with 122 additions and 159 deletions.
2 changes: 1 addition & 1 deletion timetable_kit/amtrak/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
This has very similar code to baggage.py
"""

from io import StringIO # for parsing JSON
import json
from io import StringIO # for parsing JSON

import pandas as pd

Expand Down
8 changes: 3 additions & 5 deletions timetable_kit/amtrak/accessibility_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
Requires local bad_stations.csv file: That is generated by "json_stations.py process"
"""
import json
from pathlib import Path
from io import StringIO # Needed to parse JSON

import pandas as pd

# These are mine

from timetable_kit.file_locations import get_timetable_kit_data_home

from timetable_kit.amtrak.json_stations import (
load_stations_json,
load_station_details,
)

# To filter out that which is not a train station
from timetable_kit.amtrak.station_type import is_train_station
from timetable_kit.file_locations import get_timetable_kit_data_home

# These are mine

station_stats_dir = get_timetable_kit_data_home() / "amtrak" / "station_stats"
stations_csv_path = get_timetable_kit_data_home() / "amtrak" / "stations.csv"
Expand Down
26 changes: 12 additions & 14 deletions timetable_kit/amtrak/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@
This holds a class for "AgencyAmtrak" intended to be used as a singleton.
"""
from timetable_kit.feed_enhanced import FeedEnhanced # Mostly for typechecking

from timetable_kit.generic_agency import Agency

# for patch_feed
import timetable_kit.amtrak.gtfs_patches as gtfs_patches

# for patch_add_wheelchair_boarding
import timetable_kit.amtrak.access as access

# for sleeper trains, which trains have checked baggage, major stations, etc
import timetable_kit.amtrak.special_data as special_data

# for whether stations have checked baggage
import timetable_kit.amtrak.baggage as baggage

# for patch_feed
import timetable_kit.amtrak.gtfs_patches as gtfs_patches

# for get_station_name
import timetable_kit.amtrak.json_stations as json_stations

# for get_route_name
import timetable_kit.amtrak.route_names as route_names

# for sleeper trains, which trains have checked baggage, major stations, etc
import timetable_kit.amtrak.special_data as special_data

# for get_station_name_pretty (subroutines)
import timetable_kit.text_assembly as text_assembly
from timetable_kit.text_assembly import SAFE_BR

# Map from station codes to connecting service names
# This is stashed in a class variable
from timetable_kit.amtrak.connecting_services_data import connecting_services_dict

# for get_route_name
import timetable_kit.amtrak.route_names as route_names
from timetable_kit.feed_enhanced import FeedEnhanced # Mostly for typechecking
from timetable_kit.generic_agency import Agency
from timetable_kit.text_assembly import SAFE_BR


class AgencyAmtrak(Agency):
Expand Down
6 changes: 3 additions & 3 deletions timetable_kit/amtrak/agency_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def revised_amtrak_agencies(agency):
)
# Edit the lookup table:
# This was only needed for pre-2022 Amtrak data.
agency_lookup_table[
174
] = "Amtrak Directly Operated Thruway Bus" # Is "Amtrak" in feed
agency_lookup_table[174] = (
"Amtrak Directly Operated Thruway Bus" # Is "Amtrak" in feed
)
agency_lookup_table[192] = "Thruway Bus Operator 192"
agency_lookup_table[1206] = "Thruway Bus Operator 1206"
agency_lookup_table[1207] = "Thruway Bus Operator 1207"
Expand Down
2 changes: 1 addition & 1 deletion timetable_kit/amtrak/baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Requires local copy of Amtrak stations database: That local copy is generated by "json_stations.py download"
"""

from io import StringIO # for parsing JSON
import json
from io import StringIO # for parsing JSON

import pandas as pd

Expand Down
3 changes: 1 addition & 2 deletions timetable_kit/amtrak/get_wiki_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"""

import argparse
from pathlib import Path
import re
from math import nan
from pathlib import Path

import pandas as pd


arg_parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Process the list of Amtrak stations in Wikipedia.
Expand Down
13 changes: 6 additions & 7 deletions timetable_kit/amtrak/gtfs_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"""
# TODO: all the Amtrak-specific stuff needs to be made object oriented in an "Amtrak object" perhaps

from timetable_kit.debug import debug_print
from timetable_kit.feed_enhanced import FeedEnhanced

# Add the wheelchair boarding information from JSON into the GTFS
from timetable_kit.amtrak.access import patch_add_wheelchair_boarding
from timetable_kit.debug import debug_print
from timetable_kit.feed_enhanced import FeedEnhanced

arizona_stops_list = [
# Sunset Limited
Expand Down Expand Up @@ -116,7 +115,7 @@ def patch_hiawatha(feed: FeedEnhanced):


def patch_sunset_limited(feed: FeedEnhanced):
"""Patch a bug where Sunset Limited #2 has wrong departure days.
"""Patch a bug where Sunset Limited #2 has wrong departure days.
It departs from LAX on Su/We/Fr and not Sa/Tu/Th
The bug is because it starts so late it starts on the following day in Eastern Standard Time.
Expand All @@ -139,17 +138,17 @@ def patch_sunset_limited(feed: FeedEnhanced):
debug_print(1, "Found #2 listed as running on Saturday, patching")
new_calendar.loc[index, "sunday"] = 0
new_calendar.loc[index, "monday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
if new_calendar.loc[index, "wednesday"] == 1: # This is incorrrect.
debug_print(1, "Found #2 listed as running on Tuesday, patching")
new_calendar.loc[index, "wednesday"] = 0
new_calendar.loc[index, "thursday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
if new_calendar.loc[index, "friday"] == 1: # This is incorrrect.
debug_print(1, "Found #2 listed as running on Thursday, patching")
new_calendar.loc[index, "friday"] = 0
new_calendar.loc[index, "saturday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
feed.calendar = new_calendar


Expand Down
12 changes: 4 additions & 8 deletions timetable_kit/amtrak/json_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
# will download Amtrak's station files into the './stations/' directory
# otherwise runs test case

import sys
from pathlib import Path
from io import StringIO # Needed to parse JSON
import argparse

import requests
import json # better for the details import
import random
from io import StringIO # Needed to parse JSON
from pathlib import Path
from time import sleep # Avoid slamming Amtrak's server too fast -- not needed

import pandas as pd

import random
import requests

from timetable_kit.file_locations import get_timetable_kit_data_home

Expand Down
4 changes: 2 additions & 2 deletions timetable_kit/amtrak/station_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

import sys # for sys.exit
from io import StringIO # Needed to parse JSON
import pandas as pd

# For parsing the HTML pages
import lxml.html
import pandas as pd

from timetable_kit.amtrak.json_stations import (
load_stations_json,
load_station_details_html,
)

# These are mine
from timetable_kit.debug import set_debug_level, debug_print
from timetable_kit.debug import set_debug_level

# This is a map from what we might see in the web page,
# to the key information in the form:
Expand Down
3 changes: 1 addition & 2 deletions timetable_kit/amtrak/wiki_station_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
get station names from Amtrak's JSON data.
"""

import pandas as pd
import gtfs_kit # type: ignore # Tell MyPy this has no type stubs

import pandas as pd

# Cities with multiple stations in the same city, requiring disambiguation
two_station_cities = [
Expand Down
3 changes: 2 additions & 1 deletion timetable_kit/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

# Mostly for agency defaulting
from timetable_kit import runtime_config
from timetable_kit.runtime_config import agency

# My packages: Local module imports
from timetable_kit.debug import set_debug_level
from timetable_kit.feed_enhanced import FeedEnhanced

# To initialize the feed -- does type changes
from timetable_kit.initialize import initialize_feed
from timetable_kit.runtime_config import agency

# Common arguments for the command line
from timetable_kit.timetable_argparse import (
Expand All @@ -28,6 +28,7 @@
add_debug_argument,
)


### "Compare" Debugging routines to check for changes in timetable


Expand Down
40 changes: 19 additions & 21 deletions timetable_kit/feed_enhanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,24 @@
It also gets rid of the shapes table, because it's huge and we don't use it.
"""
import datetime # for filter_for_utilities, to get current date if necessary
from collections.abc import Iterable
from dataclasses import dataclass
from typing import Type, Self, Optional

from operator import not_ # Needed for bad_service_id filter
from typing import Type, Self, Optional

import datetime # for filter_for_utilities, to get current date if necessary

from pandas import DataFrame, Series
import gtfs_kit # type: ignore # Tell MyPy this has no type stubs
from pandas import DataFrame, Series

# These are used to distinguish str types with special restrictions.
from timetable_kit.convenience_types import GTFSDate, GTFSDay

from timetable_kit.debug import debug_print
from timetable_kit.errors import (
NoTripError,
TwoTripsError,
TwoStopsError,
InputError,
)
from timetable_kit.debug import debug_print

GTFS_DAYS = (
"monday",
Expand All @@ -49,6 +46,7 @@
@dataclass
class DateRange:
"""Used to track what dates a timetable is valid for."""

latest_start_date: str
earliest_end_date: str

Expand All @@ -65,20 +63,20 @@ class FeedEnhanced(gtfs_kit.Feed):
def __init__(
self,
dist_units: str,
agency: Optional[DataFrame] = None,
stops: Optional[DataFrame] = None,
routes: Optional[DataFrame] = None,
trips: Optional[DataFrame] = None,
stop_times: Optional[DataFrame] = None,
calendar: Optional[DataFrame] = None,
calendar_dates: Optional[DataFrame] = None,
fare_attributes: Optional[DataFrame] = None,
fare_rules: Optional[DataFrame] = None,
shapes: Optional[DataFrame] = None,
frequencies: Optional[DataFrame] = None,
transfers: Optional[DataFrame] = None,
feed_info: Optional[DataFrame] = None,
attributions: Optional[DataFrame] = None,
agency: Optional[DataFrame] = None,
stops: Optional[DataFrame] = None,
routes: Optional[DataFrame] = None,
trips: Optional[DataFrame] = None,
stop_times: Optional[DataFrame] = None,
calendar: Optional[DataFrame] = None,
calendar_dates: Optional[DataFrame] = None,
fare_attributes: Optional[DataFrame] = None,
fare_rules: Optional[DataFrame] = None,
shapes: Optional[DataFrame] = None,
frequencies: Optional[DataFrame] = None,
transfers: Optional[DataFrame] = None,
feed_info: Optional[DataFrame] = None,
attributions: Optional[DataFrame] = None,
) -> None:
# doing it long form instead of the mildly cursed way gtfs_kit does, because IDEs choke on that
super().__init__(
Expand Down
37 changes: 17 additions & 20 deletions timetable_kit/feed_enhanced.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from collections.abc import Iterable
from dataclasses import dataclass
from typing import Type, Self, Optional

from pandas import DataFrame, Series
from gtfs_kit import Feed # type: ignore # Tell MyPy this has no type stubs
from pandas import DataFrame, Series

GTFS_DAYS: tuple[str, str, str, str, str, str, str]

Expand All @@ -19,28 +19,25 @@ class DateRange:
latest_start_date: str
earliest_end_date: str

def is_invalid(self) -> bool:
...

def is_one_day(self) -> bool:
...
def is_invalid(self) -> bool: ...
def is_one_day(self) -> bool: ...

class FeedEnhanced(Feed):
dist_units: str
agency: Optional[DataFrame] = None
stops: Optional[DataFrame] = None
routes: Optional[DataFrame] = None
trips: Optional[DataFrame] = None
stop_times: Optional[DataFrame] = None
calendar: Optional[DataFrame] = None
calendar_dates: Optional[DataFrame] = None
fare_attributes: Optional[DataFrame] = None
fare_rules: Optional[DataFrame] = None
shapes: Optional[DataFrame] = None
frequencies: Optional[DataFrame] = None
transfers: Optional[DataFrame] = None
feed_info: Optional[DataFrame] = None
attributions: Optional[DataFrame] = None
agency: Optional[DataFrame] = None
stops: Optional[DataFrame] = None
routes: Optional[DataFrame] = None
trips: Optional[DataFrame] = None
stop_times: Optional[DataFrame] = None
calendar: Optional[DataFrame] = None
calendar_dates: Optional[DataFrame] = None
fare_attributes: Optional[DataFrame] = None
fare_rules: Optional[DataFrame] = None
shapes: Optional[DataFrame] = None
frequencies: Optional[DataFrame] = None
transfers: Optional[DataFrame] = None
feed_info: Optional[DataFrame] = None
attributions: Optional[DataFrame] = None

@classmethod
def enhance(cls: Type[Self], regular_feed: Feed) -> Self: ...
Expand Down
1 change: 1 addition & 0 deletions timetable_kit/file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from pathlib import Path

from timetable_kit.errors import InputError


Expand Down
Loading

0 comments on commit 60a2d62

Please sign in to comment.