Skip to content
Snippets Groups Projects
Commit 288f4dbb authored by Rob Moss's avatar Rob Moss
Browse files

Format code in docstrings

This requires ruff 0.1.9 or newer.
parent 2ceaacf9
Branches
Tags
No related merge requests found
Pipeline #68530 passed
......@@ -88,6 +88,6 @@ def docs(session):
def ruff(session):
"""Check code for linter warnings and formatting issues."""
check_files = ['src', 'tests', 'doc', 'noxfile.py']
session.install('ruff ~= 0.1.2')
session.install('ruff ~= 0.1.9')
session.run('ruff', 'check', *check_files)
session.run('ruff', 'format', '--diff', *check_files)
......@@ -59,14 +59,17 @@ addopts = """\
"""
[tool.ruff]
# Enable pyflakes (F), pycodestyle (E, W), and flake8-bugbear (B).
select = ["F", "E", "W", "B"]
line-length = 78
target-version = "py38"
[tool.ruff.per-file-ignores]
[tool.ruff.lint]
# Enable pyflakes (F), pycodestyle (E, W), and flake8-bugbear (B).
select = ["F", "E", "W", "B"]
[tool.ruff.lint.per-file-ignores]
# Ignore "Ambiguous variable name" for SIR state variable `I`.
"sir.py" = ["E741"]
[tool.ruff.format]
quote-style = "single"
docstring-code-format = true
......@@ -53,18 +53,19 @@ def read_table(path, columns, comment='#', encoding='utf-8'):
>>> from pypfilt.io import date_column, read_table
>>> import numpy as np
>>> import datetime
>>> path = "input_data.ssv"
>>> path = 'input_data.ssv'
>>> with open(path, 'w') as f:
... _ = f.write('time value\\n')
... _ = f.write('2020-01-01 1\\n')
... _ = f.write('2020-01-02 3\\n')
... _ = f.write('2020-01-03 5\\n')
... _ = f.write('time value\\n')
... _ = f.write('2020-01-01 1\\n')
... _ = f.write('2020-01-02 3\\n')
... _ = f.write('2020-01-03 5\\n')
>>> columns = [date_column('time'), ('value', np.int64)]
>>> data = read_table(path, columns)
>>> isinstance(data['time'][0], datetime.datetime)
True
>>> observations = [{'time': row['time'], 'value': row['value']}
... for row in data]
>>> observations = [
... {'time': row['time'], 'value': row['value']} for row in data
... ]
>>> # Remove the input file when it is no longer needed.
>>> import os
>>> os.remove(path)
......@@ -162,6 +163,7 @@ def read_fields(time_scale, path, fields, comment='#', encoding='utf-8'):
import numpy as np
import pypfilt.io
def load_time_series(self, filename, time_scale):
fields = [pypfilt.io.time_field('time'), ('value', np.float64)]
return pypfilt.io.read_fields(time_scale, filename, fields)
......@@ -240,10 +242,10 @@ def read_lookup_table(path, time, dtype='f8', comment='#', encoding='utf-8'):
>>> from pypfilt.io import read_lookup_table, lookup
>>> from pypfilt.time import Datetime
>>> import datetime
>>> path = "input_data.ssv"
>>> path = 'input_data.ssv'
>>> with open(path, 'w') as f:
... _ = f.write('time value1 value2 value3\\n')
... _ = f.write('2020-01-01 1.0 1.5 2.0\\n')
... _ = f.write('time value1 value2 value3\\n')
... _ = f.write('2020-01-01 1.0 1.5 2.0\\n')
>>> time = Datetime()
>>> table = read_lookup_table(path, time)
>>> isinstance(table['time'][0], datetime.datetime)
......
......@@ -182,6 +182,7 @@ class Obs(abc.ABC):
import numpy as np
import pypfilt.io
def from_file(self, filename, time_scale):
fields = [pypfilt.io.time_field('time'), ('value', np.float64)]
return pypfilt.io.read_fields(time_scale, filename, fields)
......@@ -305,7 +306,6 @@ class Univariate(Obs):
... expect = snapshot.state_vec['x']
... sdev = self.settings['parameters']['sdev']
... return scipy.stats.norm(loc=expect, scale=self.sdev)
...
>>> observation_unit = 'x'
>>> settings = {'parameters': {'sdev': 0.1}}
>>> obs_model = MyObsModel(observation_unit, settings)
......
......@@ -158,8 +158,9 @@ def load_instances(sources):
>>> data_file = 'output.hdf5'
>>> for instance in pypfilt.load_instances(config_file):
... context = instance.build_context()
... state = pypfilt.forecast(context, forecast_times,
... filename=data_file)
... state = pypfilt.forecast(
... context, forecast_times, filename=data_file
... )
>>> # Remove the output file when it is no longer needed.
>>> import os
>>> os.remove(data_file)
......
......@@ -226,11 +226,14 @@ def repack(svec, astype=float):
>>> import numpy as np
>>> from pypfilt.state import repack
>>> xs = np.array([(1.2, (2.2, 3.2)), (4.2, (5.2, 6.2))],
... dtype=[('x', float), ('y', float, 2)])
>>> xs = np.array(
... [(1.2, (2.2, 3.2)), (4.2, (5.2, 6.2))],
... dtype=[('x', float), ('y', float, 2)],
... )
>>> ys = repack(xs)
>>> assert np.array_equal(ys, np.array([[1.2, 2.2, 3.2],
... [4.2, 5.2, 6.2]]))
>>> assert np.array_equal(
... ys, np.array([[1.2, 2.2, 3.2], [4.2, 5.2, 6.2]])
... )
"""
def is_compat(dt):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment