Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofix all notebook linting errors #290

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

mfitz
Copy link
Contributor

@mfitz mfitz commented Dec 19, 2024

Before

nbqa ruff examples/
examples/02a_tabular_read_write.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
  |
1 |   # %%NBQA-CELL-SEP48762f
2 | / import os
3 | |
4 | | import pandas as pd
5 | | from pam import read
6 | |
7 | | # %%NBQA-CELL-SEP48762f
  | |_^ I001
8 |   trips = pd.read_csv(
9 |       os.path.join("data", "example_data", "example_travel_diaries.csv"), index_col="uid"
  |
  = help: Organize imports

examples/03_read_modify_write.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | | from collections import defaultdict
 4 | |
 5 | | import geopandas as gp
 6 | | import pandas as pd
 7 | | from matplotlib import pyplot as plt
 8 | | from pam import policy, read
 9 | | from pam.policy import apply_policies
10 | |
11 | | hash(0xFE7F7A94)
   | |_^ I001
12 |
13 |   # %%NBQA-CELL-SEP48762f
   |
   = help: Organize imports

examples/04_point_sampling.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | |
 4 | | import geopandas as gp
 5 | | import pandas as pd
 6 | | from matplotlib import pyplot as plt
 7 | | from pam import read
 8 | | from pam.samplers.spatial import RandomPointSampler
 9 | |
10 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
11 |   trips = pd.read_csv(
12 |       os.path.join("data", "example_data", "example_travel_diaries.csv"), index_col="uid"
   |
   = help: Organize imports

examples/05_activity_plots.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | |
 4 | | import pandas as pd
 5 | | from pam import read
 6 | | from pam.plot.stats import plot_activity_times, plot_leg_times
 7 | |
 8 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
 9 |   data_path = os.path.join("data", "example_data")
10 |   trips = pd.read_csv(os.path.join(data_path, "example_travel_diaries.csv"))
   |
   = help: Organize imports

examples/07_travel_survey_to_matsim.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | | from copy import deepcopy
 4 | |
 5 | | import geopandas as gp
 6 | | import pandas as pd
 7 | | from pam import read, write
 8 | | from pam.core import Population
 9 | | from pam.plot.stats import plot_activity_times, plot_leg_times
10 | | from pam.samplers.basic import freq_sample
11 | | from pam.samplers.spatial import RandomPointSampler
12 | |
13 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
14 |   use_dummy_data = True
   |
   = help: Organize imports

examples/08_toy_matsim_population.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | |
 4 | | import geopandas as gp
 5 | | import matplotlib.pyplot as plt
 6 | | import numpy as np
 7 | | import pandas as pd
 8 | | from pam.activity import Activity, Leg
 9 | | from pam.core import Household, Person, Population
10 | | from pam.plot.stats import plot_activity_times
11 | | from pam.read import load_travel_diary
12 | | from pam.report.benchmarks import distance_counts, duration_counts
13 | | from pam.samplers import facility
14 | | from pam.utils import minutes_to_datetime as mtdt
15 | | from pam.variables import END_OF_DAY
16 | | from pam.write import to_csv, write_matsim, write_od_matrices
17 | |
18 | | hash(0x40F3F06D)
   | |_^ I001
19 |
20 |   # %%NBQA-CELL-SEP48762f
   |
   = help: Organize imports

examples/10_advanced_spatial_sampling.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import logging
 3 | |
 4 | | import geopandas as gp
 5 | | import matplotlib.pyplot as plt
 6 | | import numpy as np
 7 | | import pam
 8 | | import pandas as pd
 9 | | from pam.activity import Activity, Leg
10 | | from pam.core import Household, Person, Population
11 | | from pam.samplers import facility
12 | | from pam.utils import minutes_to_datetime
13 | | from shapely.geometry import Point, Polygon
14 | |
15 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
16 |   # create random spatial data
   |
   = help: Organize imports

examples/13_Advanced_Freight_Synthesis.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import os
 3 | | from datetime import date
 4 | |
 5 | | import geopandas as gp
 6 | | import matplotlib
 7 | | import numpy as np
 8 | | import pandas as pd
 9 | | from matplotlib import pyplot as plt
10 | | from pam.core import Household, Person, Population
11 | | from pam.samplers import tour
12 | | from pam.samplers.facility import FacilitySampler
13 | |
14 | | matplotlib.style.use("ggplot")
   | |_^ I001
15 |
16 |   # %%NBQA-CELL-SEP48762f
   |
   = help: Organize imports

examples/14_Advanced_Plan_Cropping.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / from copy import deepcopy
 3 | |
 4 | | import geopandas as gp
 5 | | import matplotlib.pyplot as plt
 6 | | from pam.activity import Activity, Leg, Plan
 7 | | from pam.core import Household, Person, Population
 8 | | from pam.operations import cropping
 9 | | from pam.utils import minutes_to_datetime as mtdt
10 | | from pam.variables import END_OF_DAY
11 | | from shapely.geometry import Point, Polygon
12 | |
13 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
   |
   = help: Organize imports

examples/15_advanced_choice_modelling.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import logging
 3 | | import os
 4 | | import random
 5 | |
 6 | | import numpy as np
 7 | | import pandas as pd
 8 | | from pam.operations.cropping import link_population
 9 | | from pam.planner import choice_location as choice
10 | | from pam.planner.od import ODFactory, ODMatrix
11 | | from pam.read import read_matsim
12 | | from prettytable import PrettyTable
13 | |
14 | | logging.basicConfig(level=logging.DEBUG)
   | |_^ I001
15 |   random.seed(0)
   |
   = help: Organize imports

examples/17_advanced_discretionary_locations.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import logging
 3 | | import random
 4 | | from copy import deepcopy
 5 | |
 6 | | import numpy as np
 7 | | import pandas as pd
 8 | | from pam.activity import Activity, Leg, Plan
 9 | | from pam.location import Location
10 | | from pam.planner.choice_location import DiscretionaryTripOD, DiscretionaryTrips
11 | | from pam.planner.od import ODFactory, ODMatrix
12 | | from pam.planner.utils_planner import get_trip_chains_either_anchor
13 | | from pam.utils import minutes_to_datetime as mtdt
14 | | from pam.variables import END_OF_DAY
15 | | from prettytable import PrettyTable
16 | | from shapely.geometry import Point
17 | |
18 | | logging.getLogger("pam").setLevel(logging.DEBUG)
   | |_^ I001
19 |   random.seed(0)
   |
   = help: Organize imports

examples/18_advanced_ipf.ipynb:cell_1:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 |   # %%NBQA-CELL-SEP48762f
 2 | / import itertools
 3 | |
 4 | | import pandas as pd
 5 | | from pam.core import Person, Population
 6 | | from pam.planner import ipf
 7 | |
 8 | | # %%NBQA-CELL-SEP48762f
   | |_^ I001
 9 |   zone_data = pd.DataFrame(
10 |       {
   |
   = help: Organize imports

Found 12 errors.
[*] 12 fixable with the `--fix` option.

This confirmed the results of the hosted pre-commit check.

Automatically Fixing Errors

nbqa ruff --fix examples/
Found 12 errors (12 fixed, 0 remaining).

Local pre-commit check

git status
On branch fix-notebook-linting-errors
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   examples/02a_tabular_read_write.ipynb
	modified:   examples/03_read_modify_write.ipynb
	modified:   examples/04_point_sampling.ipynb
	modified:   examples/05_activity_plots.ipynb
	modified:   examples/07_travel_survey_to_matsim.ipynb
	modified:   examples/08_toy_matsim_population.ipynb
	modified:   examples/10_advanced_spatial_sampling.ipynb
	modified:   examples/13_Advanced_Freight_Synthesis.ipynb
	modified:   examples/14_Advanced_Plan_Cropping.ipynb
	modified:   examples/15_advanced_choice_modelling.ipynb
	modified:   examples/17_advanced_discretionary_locations.ipynb
	modified:   examples/18_advanced_ipf.ipynb

git commit -m "Autofix all notebook linting errors"
check for added large files..............................................Passed
black................................................(no files to check)Skipped
ruff.................................................(no files to check)Skipped
nbqa-black...............................................................Passed
nbqa-ruff................................................................Passed
forbidden files......................................(no files to check)Skipped
[fix-notebook-linting-errors 05d19fc] Autofix all notebook linting errors

After

nbqa ruff examples/
All checks passed!

The hosted pre-commit check agrees.

@mfitz mfitz merged commit 71c71ca into main Dec 19, 2024
16 checks passed
@mfitz mfitz deleted the fix-notebook-linting-errors branch December 19, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example notebooks have linting errors
2 participants