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

Fix CI Build matplotlib error #288

Merged
merged 3 commits into from
Dec 19, 2024
Merged

Fix CI Build matplotlib error #288

merged 3 commits into from
Dec 19, 2024

Conversation

mfitz
Copy link
Contributor

@mfitz mfitz commented Dec 18, 2024

The fix happens in src/pam/plot/stats.py; all of the other changed files are a result of a cruft update.

Before the Change

One of the unit tests was broken:

Screenshot 2024-12-18 at 19 10 44 Screenshot 2024-12-18 at 19 11 00

After the Change

The build is fixed:

Screenshot 2024-12-18 at 19 11 31 Screenshot 2024-12-18 at 19 11 49

Is the Change Safe?

The previous attempt to set a label on the x-axis of plots (via axis.xaxis.set_label("")) was:

  • effectively a no-op, setting no label, as discussed here
  • attempting to set an empty string as the label in any case
  • failing silently in matplotlib < 3.10, but... noisily in matplotlib 3.10

In functional terms, we have changed nothing, but we now avoid the error caused by the breaking change in matplotlib 3.10.

Checklist

Not Applicable

Any checks which are not relevant to the PR can be pre-checked by the PR creator.
All others should be checked by the reviewer(s).
You can add extra checklist items here if required by the PR.

  • CHANGELOG updated
  • Tests added to cover contribution
  • Documentation updated

@mfitz mfitz changed the title Fix ci build matplotlib error Fix CI Build matplotlib error Dec 18, 2024
4. Commit your changes to the feature branch (you should have `pre-commit` installed to ensure your code is correctly formatted when you commit changes).
5. Push the branch to GitHub (`git push origin new-fix-or-feature`).
6. On GitHub, create a new [pull request](https://github.com/arup-group/pam/pull/new/main) from the feature branch.
1. Create a feature branch to work on in your fork (`git checkout -b new-fix-or-feature`).
Copy link
Contributor Author

@mfitz mfitz Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numbered list looks broken from the upstream cookie cutter - any ideas @brynpickering ?

@KasiaKoz
Copy link
Contributor

The pre-commit.ci - pr check is failing, are we happy to go merge with that failure?

@mfitz
Copy link
Contributor Author

mfitz commented Dec 19, 2024

The pre-commit.ci - pr check is failing, are we happy to go merge with that failure?

As far as I can see, that's failing on a notebook check. I can't see what the failure is, nor can I see an obvious way to re-run the job. No notebooks were harmed have been changed in this PR, and the CI checks all pass. If the worst comes to the worst, I am okay with merging this as is. The pre-commit job seems to fail a lot more than it passes.

@brynpickering - how do we interpret this? Is there a way to see debug details? Is there a way to re-run the job? I can't see a way to run it locally, given that I have no staged changes:

pre-commit
check for added large files..........................(no files to check)Skipped
black................................................(no files to check)Skipped
ruff.................................................(no files to check)Skipped
nbqa-black...........................................(no files to check)Skipped
nbqa-ruff............................................(no files to check)Skipped
forbidden files......................................(no files to check)Skipped

@mfitz
Copy link
Contributor Author

mfitz commented Dec 19, 2024

pre-commit.ci run

@mfitz
Copy link
Contributor Author

mfitz commented Dec 19, 2024

The pre-commit.ci - pr check is failing, are we happy to go merge with that failure?

Okay, I pip installed nbqa locally and ran ruff on the examples dir:

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.

All of the errors are about the formatting/sorting of import blocks.

I could (auto)fix them in this branch, or we could merge this PR as is and fix them in a dedicated branch. Which do you prefer @brynpickering @KasiaKoz ? My preference is to fix that in a separate PR.

Copy link
Contributor

@KasiaKoz KasiaKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could (auto)fix them in this branch, or we could merge this PR as is and fix them in a dedicated branch. Which do you prefer @brynpickering @KasiaKoz ? My preference is to fix that in a separate PR.

Yup, agree with separate PR

@mfitz mfitz merged commit 98ef2b4 into main Dec 19, 2024
15 of 16 checks passed
@mfitz mfitz deleted the fix_ci_build_matplotlib_error branch December 19, 2024 14:41
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.

Fix the CI build
3 participants