Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
import numpy as np
import scipy as sp
import pandas as pd
import geopandas as gpd

Import Ordering

The isort package should manage this for you but the convention is that imports are ordered into the following sections:

  1. Standard library imports
  2. External library imports
  3. Imports within the same package

Within each section, imports are sorted in alphabetical order.

Consider the following example in the Pre-processing module.

Code Block
languagepy
# stdlib imports
import argparse
import collections
import multiprocessing
import subprocess
import tempfile
from pathlib import Path
from typing import Annotated, Generator

# external package imports
import numpy as np
import pyproj
import typer
from qcore import binary_version

# internal imports
from srf_generation import realisation
from srf_generation.fault import Fault

Notice that the qcore import is considered external to the Pre-processing package, and is hence sorted into the external package imports section.

I/O Functions

The typical convention is that functions that read or write to files should be given the file path as a parameter, rather than a file object.

...

Code Block
languagepy
def write_gsf(filepath: Path):

Rather than:

Code Block
languagepy
def write_gsf(file_handle: TextIO):

...