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

Introduce Ruff #821

Merged
merged 18 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/black.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following persons contributed to the development of the |pyam| package:
- Philip Hackstock `@phackstock <https://github.com/phackstock>`_
- Pietro Monticone `@pitmonticone <https://github.com/pitmonticone>`
- Edward Byers `@byersiiasa <https://github.com/byersiiasa>`
- Fridolin Glatter `@glatterf42 <https://github.com/glatterf42>`

| The core maintenance of the |pyam| package is done by
the *Scenario Services & Scientific Software* research theme
Expand Down
5 changes: 4 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ For contributions to the code base, please use GitHub *Pull Requests*,
including a detailed description of the new feature and unit tests
to illustrate the intended functionality.
Code submitted via pull requests must adhere to the `pep8`_ style formats
and the documentation should follow the `numpydoc docstring guide`_.
and the documentation should follow the `numpydoc docstring guide`_. We are
using `ruff`_ to check the code style.

We do not require users to sign a *Contributor License Agreement*, because we
believe that when posting ideas or submitting code to an open-source project,
Expand All @@ -35,3 +36,5 @@ are made in the spirit of open collaborative development.
.. _`pep8`: https://www.python.org/dev/peps/pep-0008/

.. _`numpydoc docstring guide`: https://numpydoc.readthedocs.io/en/latest/format.html

.. _`ruff`: https://docs.astral.sh/ruff/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pyam: analysis & visualization <br /> of integrated-assessment and macro-energy
[![last-release](https://img.shields.io/github/release-date/iamconsortium/pyam?logo=github&label=last%20release)](https://github.com/IAMconsortium/pyam/releases)

<!-- replace python version by dynamic reference to pypi once Python versions are configured there -->
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Code style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![python](https://img.shields.io/badge/python-≥3.10,<3.12-blue?logo=python&logoColor=white)](https://github.com/IAMconsortium/pyam)
[![pytest](https://img.shields.io/github/actions/workflow/status/iamconsortium/pyam/pytest.yml?logo=GitHub&label=pytest)](https://github.com/IAMconsortium/pyam/actions/workflows/pytest.yml)
[![ReadTheDocs](https://readthedocs.org/projects/pyam-iamc/badge/?version=latest)](https://pyam-iamc.readthedocs.io/en/latest/?badge=latest)
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Next release

- [#824](https://github.com/IAMconsortium/pyam/pull/824) Update ixmp4 requirement to >=0.7.1
- [#821](https://github.com/IAMconsortium/pyam/pull/821) Introduce ruff
- [#818](https://github.com/IAMconsortium/pyam/pull/818) Use context manager for reading Excel file
- [#813](https://github.com/IAMconsortium/pyam/pull/813) Fix a corner case in region-aggregation with missing data
- [#797](https://github.com/IAMconsortium/pyam/pull/797) Add `to_ixmp4()` method to write to an **ixmp4** platform
Expand Down
106 changes: 73 additions & 33 deletions docs/R_tutorials/pyam_R_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
"cell_type": "code",
"execution_count": 1,
"id": "specified-administration",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"name": "stderr",
Expand All @@ -87,7 +91,7 @@
}
],
"source": [
"require(reticulate)"
"require(reticulate)\n"
]
},
{
Expand All @@ -104,10 +108,14 @@
"cell_type": "code",
"execution_count": 2,
"id": "varied-functionality",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"use_condaenv()"
"use_condaenv()\n"
]
},
{
Expand All @@ -122,10 +130,14 @@
"cell_type": "code",
"execution_count": 3,
"id": "registered-stack",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"pyam <- import(\"pyam\")"
"pyam <- import(\"pyam\")\n"
]
},
{
Expand All @@ -143,7 +155,11 @@
"cell_type": "code",
"execution_count": 4,
"id": "increased-substance",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -196,15 +212,15 @@
],
"source": [
"data <- data.frame(\n",
" model=c('model_a', 'model_a', 'model_a'),\n",
" scenario=c('scen_a', 'scen_a', 'scen_b'),\n",
" region=c('World', 'World', 'World'),\n",
" variable=c('Primary Energy', 'Primary Energy|Coal', 'Primary Energy'),\n",
" unit=c('EJ/yr', 'EJ/yr', 'EJ/yr'),\n",
" \"2005\"=c(1, 0.5, 2),\n",
" \"2010\"=c(6, 3, 7)\n",
" model = c(\"model_a\", \"model_a\", \"model_a\"),\n",
" scenario = c(\"scen_a\", \"scen_a\", \"scen_b\"),\n",
" region = c(\"World\", \"World\", \"World\"),\n",
" variable = c(\"Primary Energy\", \"Primary Energy|Coal\", \"Primary Energy\"),\n",
" unit = c(\"EJ/yr\", \"EJ/yr\", \"EJ/yr\"),\n",
" \"2005\" = c(1, 0.5, 2),\n",
" \"2010\" = c(6, 3, 7)\n",
")\n",
"data"
"data\n"
]
},
{
Expand All @@ -226,7 +242,11 @@
"cell_type": "code",
"execution_count": 5,
"id": "spread-spring",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"data": {
Expand All @@ -250,7 +270,7 @@
],
"source": [
"df <- pyam$IamDataFrame(data)\n",
"df"
"df\n"
]
},
{
Expand All @@ -269,7 +289,11 @@
"cell_type": "code",
"execution_count": 6,
"id": "different-consensus",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -333,7 +357,7 @@
}
],
"source": [
"df$data"
"df$data\n"
]
},
{
Expand All @@ -359,17 +383,25 @@
"cell_type": "code",
"execution_count": 7,
"id": "urban-eclipse",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"x <- df$interpolate(as.integer(2007), inplace=TRUE)"
"x <- df$interpolate(as.integer(2007), inplace = TRUE)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "confident-lebanon",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -445,7 +477,7 @@
}
],
"source": [
"df$data"
"df$data\n"
]
},
{
Expand All @@ -466,23 +498,31 @@
"cell_type": "code",
"execution_count": 9,
"id": "91c7fddf",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"df = pyam$read_iiasa(\n",
" 'iamc15',\n",
" model='MESSAGEix*', \n",
" variable=c('Emissions|CO2', 'Primary Energy|Coal'), \n",
" region='World',\n",
" meta=c('category')\n",
")"
"df <- pyam$read_iiasa(\n",
" \"iamc15\",\n",
" model = \"MESSAGEix*\",\n",
" variable = c(\"Emissions|CO2\", \"Primary Energy|Coal\"),\n",
" region = \"World\",\n",
" meta = c(\"category\")\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "377eac4c",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -510,7 +550,7 @@
}
],
"source": [
"df"
"df\n"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
from datetime import datetime
import pyam

from plotly.io._sg_scraper import plotly_sg_scraper

import pyam

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -362,7 +363,7 @@

<a href="https://docs.ece.iiasa.ac.at/ixmp4/">
<code class="xref py py-class docutils literal notranslate"><span class="pre">
ixmp4</span></code></a>
ixmp4</span></code></a>

.. |br| raw:: html

Expand All @@ -372,4 +373,4 @@

<a href="https://github.com/frictionlessdata/datapackage-py#package">read the docs</a>

"""
""" # noqa: E501
4 changes: 2 additions & 2 deletions docs/examples/plot_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam
from pyam.plotting import add_net_values_to_bar_plot

df = pyam.IamDataFrame("tutorial_data.csv")
df
Expand Down Expand Up @@ -78,8 +80,6 @@
# Sometimes, stacked bar charts have negative entries.
# In that case, it helps to add a line showing the net value.

from pyam.plotting import add_net_values_to_bar_plot

fig, ax = plt.subplots()
data.plot.bar(
ax=ax, bars="region", stacked=True, title="CO2 emissions by region", cmap="tab20"
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/plot_sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#
# Make sure to place the data file in the same folder as this script/notebook.

import pyam
import plotly

import pyam

df = pyam.IamDataFrame("sankey_data.csv")
df

Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_secondary_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
1 change: 1 addition & 0 deletions docs/examples/plot_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Make sure to place the data file in the same folder as this script/notebook.

import matplotlib.pyplot as plt

import pyam

df = pyam.IamDataFrame("tutorial_data.csv")
Expand Down
Loading
Loading