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

Add ruff for linting, remove flake8, remove isort #114

Merged
merged 35 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bd8874c
run ruff and fix errors
gsheni Dec 30, 2022
e71f138
fix lint workflow
gsheni Dec 30, 2022
c3dca06
fix pre-commit order
gsheni Dec 30, 2022
17d2173
fix Makefile order
gsheni Dec 30, 2022
503d072
fix ruff settings
gsheni Dec 30, 2022
b713247
fix ruff settings
gsheni Dec 30, 2022
bb811c5
remove isort, ruff has same function
gsheni Dec 30, 2022
8b79c98
fix imports
gsheni Dec 30, 2022
af8e3f7
fix rules
gsheni Dec 30, 2022
67237b0
fix func
gsheni Dec 30, 2022
6e884f3
consistent line length
gsheni Jan 2, 2023
bb215e4
preview line length changes
gsheni Jan 2, 2023
3e655ad
fix conflict
gsheni Jan 2, 2023
0cdfa6b
Merge branch 'main' into ruff
gsheni Jan 2, 2023
8e3d95f
shortening some lines
gsheni Jan 2, 2023
761e7b4
shortening some lines
gsheni Jan 2, 2023
da5ae91
passes lint
gsheni Jan 2, 2023
06972d5
fix docstrings
gsheni Jan 2, 2023
9cd0267
fix docstrings
gsheni Jan 3, 2023
740be4b
fix long line
gsheni Jan 3, 2023
04f8c82
more docstring fixes
gsheni Jan 3, 2023
b4a18e6
more docstring fixes
gsheni Jan 3, 2023
2c40bfc
more docstring fixes
gsheni Jan 3, 2023
5a63367
more docstring fixes
gsheni Jan 3, 2023
d0a5974
more docstring fixes
gsheni Jan 3, 2023
19ae08a
lint
gsheni Jan 3, 2023
a0686b7
more docstring fixes
gsheni Jan 3, 2023
fd27f2d
lint
gsheni Jan 3, 2023
c742cad
more docstring fixes
gsheni Jan 3, 2023
fcff613
more docstring fixes
gsheni Jan 3, 2023
ef88cda
one last docstring
gsheni Jan 3, 2023
3de8ccc
one last docstring
gsheni Jan 3, 2023
09f14ab
one last docstring, promise
gsheni Jan 3, 2023
f81c193
Merge branch 'main' into ruff
kmax12 Jan 3, 2023
830399c
Update isone.py
kmax12 Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 2 additions & 14 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: Lint Check
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- main

on: [pull_request]
jobs:
lint_test:
name: 3.11 lint check
Expand All @@ -19,11 +13,5 @@ jobs:
- name: Install package with dev deps
run: |
python -m pip install -e ".[dev]"
- name: Run lint test
- name: Run lint check
run: make lint
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
11 changes: 8 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/MarcoGorelli/absolufy-imports
Expand All @@ -16,14 +17,18 @@ repos:
hooks:
- id: add-trailing-comma
name: Add trailing comma
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
hooks:
- id: isort
- id: validate-pyproject
- repo: https://github.com/python/black
rev: 22.12.0
hooks:
- id: black
args: [--target-version=py311]
additional_dependencies: [".[jupyter]"]
types_or: [python, jupyter]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.202
hooks:
- id: ruff
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ installdeps-docs:

.PHONY: lint
lint:
isort --check-only gridstatus/
black gridstatus/ -t py311 --check
ruff gridstatus/

.PHONY: lint-fix
lint-fix:
black gridstatus/ -t py311
isort gridstatus/
ruff gridstatus/ --fix

.PHONY: upgradepip
upgradepip:
Expand Down
33 changes: 6 additions & 27 deletions docs/Examples/spp/LMP Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@
}
],
"source": [
"df = iso.get_lmp(\n",
" date=\"latest\",\n",
" market=\"REAL_TIME_5_MIN\"\n",
")\n",
"df = iso.get_lmp(date=\"latest\", market=\"REAL_TIME_5_MIN\")\n",
"df"
]
},
Expand Down Expand Up @@ -333,9 +330,7 @@
],
"source": [
"df = iso.get_lmp(\n",
" date=\"latest\",\n",
" market=\"REAL_TIME_5_MIN\",\n",
" location_type=\"SETTLEMENT_LOCATION\"\n",
" date=\"latest\", market=\"REAL_TIME_5_MIN\", location_type=\"SETTLEMENT_LOCATION\"\n",
")\n",
"df.head(5)"
]
Expand Down Expand Up @@ -500,11 +495,7 @@
}
],
"source": [
"df = iso.get_lmp(\n",
" date=\"latest\",\n",
" market=\"REAL_TIME_5_MIN\",\n",
" location_type=\"Interface\"\n",
")\n",
"df = iso.get_lmp(date=\"latest\", market=\"REAL_TIME_5_MIN\", location_type=\"Interface\")\n",
"df.head(5)"
]
},
Expand Down Expand Up @@ -637,11 +628,7 @@
}
],
"source": [
"df = iso.get_lmp(\n",
" date=\"today\",\n",
" market=\"REAL_TIME_5_MIN\",\n",
" location_type=\"Interface\"\n",
")\n",
"df = iso.get_lmp(date=\"today\", market=\"REAL_TIME_5_MIN\", location_type=\"Interface\")\n",
"df.head(5)"
]
},
Expand Down Expand Up @@ -776,11 +763,7 @@
}
],
"source": [
"df = iso.get_lmp(\n",
" date=\"today\",\n",
" market=\"DAY_AHEAD_HOURLY\",\n",
" location_type=\"Hub\"\n",
")\n",
"df = iso.get_lmp(date=\"today\", market=\"DAY_AHEAD_HOURLY\", location_type=\"Hub\")\n",
"df.head(5)"
]
},
Expand Down Expand Up @@ -915,11 +898,7 @@
}
],
"source": [
"df = iso.get_lmp(\n",
" date=\"today\",\n",
" market=\"DAY_AHEAD_HOURLY\",\n",
" location_type=\"Interface\"\n",
")\n",
"df = iso.get_lmp(date=\"today\", market=\"DAY_AHEAD_HOURLY\", location_type=\"Interface\")\n",
"df.head(5)"
]
}
Expand Down
1 change: 0 additions & 1 deletion docs/update_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gridstatus
from gridstatus.utils import make_availability_table, make_lmp_availability_table


Expand Down
4 changes: 1 addition & 3 deletions gridstatus/caiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import requests
import tabula

import gridstatus
from gridstatus import utils
from gridstatus.base import FuelMix, GridStatus, ISOBase, Markets, NotSupported
from gridstatus.decorators import support_date_range
Expand Down Expand Up @@ -560,7 +559,7 @@ def get_curtailment(self, date, verbose=False):
with io.StringIO() as buf, redirect_stderr(buf):
try:
tables = tabula.read_pdf(pdf, pages="all")
except:
except Exception:
print(buf.getvalue())
raise RuntimeError("Problem Reading PDF")

Expand Down Expand Up @@ -854,7 +853,6 @@ def _caiso_handle_start_end(date, end):

# check if any files are missing
import glob
import os

files = glob.glob("caiso_curtailment/*.csv")
dates = (
Expand Down
6 changes: 1 addition & 5 deletions gridstatus/isone.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import io
import math
import re
from heapq import merge
from tabnanny import verbose

import pandas as pd
import requests

import gridstatus
from gridstatus import utils
from gridstatus.base import (
FuelMix,
Expand Down Expand Up @@ -558,7 +554,7 @@ def _make_request(url, skiprows, verbose):
attempt = 0
while attempt < 3:
# make first get request to get cookies set
r1 = s.get(
_ = s.get(
"https://www.iso-ne.com/isoexpress/web/reports/operations/-/tree/gen-fuel-mix",
)

Expand Down
1 change: 0 additions & 1 deletion gridstatus/miso.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pandas as pd
import requests
from pandas import Timestamp

from gridstatus import utils
from gridstatus.base import FuelMix, ISOBase, Markets, NotSupported
Expand Down
3 changes: 1 addition & 2 deletions gridstatus/nyiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
InterconnectionQueueStatus,
ISOBase,
Markets,
_interconnection_columns,
)
from gridstatus.decorators import support_date_range

Expand Down Expand Up @@ -86,7 +85,7 @@ def get_fuel_mix(self, date, end=None, verbose=False):

if data["status"] != "success":
raise RuntimeError(
f"Failed to get latest fuel mix. Check if NYISO's API is down.",
"Failed to get latest fuel mix. Check if NYISO's API is down.",
)

mix_df = pd.DataFrame(data["data"])
Expand Down
7 changes: 3 additions & 4 deletions gridstatus/pjm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import requests
import tqdm

import gridstatus
from gridstatus import utils
from gridstatus.base import FuelMix, ISOBase, Markets, NotSupported
from gridstatus.decorators import (
Expand Down Expand Up @@ -343,7 +342,7 @@ def get_lmp(
data = data[data["Location Type"] == location_type]

if locations is not None and locations != "ALL":
data = gridstatus.utils.filter_lmp_locations(
data = utils.filter_lmp_locations(
data,
map(int, locations),
)
Expand All @@ -370,10 +369,10 @@ def _get_pjm_json(
final_params.update(default_params)

if start is not None:
start = gridstatus.utils._handle_date(start)
start = utils._handle_date(start)

if end:
end = gridstatus.utils._handle_date(end)
end = utils._handle_date(end)
else:
end = start + pd.DateOffset(days=1)

Expand Down
2 changes: 0 additions & 2 deletions gridstatus/tests/test_caiso.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

import gridstatus


Expand Down
2 changes: 1 addition & 1 deletion gridstatus/tests/test_ercot.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_ercot_get_two_days_ago_day_ahead_hourly_zone():
def test_ercot_get_dam_latest_day_ahead_hourly_zone_should_raise_exception():
iso = gridstatus.Ercot()
with pytest.raises(ValueError):
df = iso.get_spp(
iso.get_spp(
date="latest",
market=Markets.DAY_AHEAD_HOURLY,
location_type="zone",
Expand Down
13 changes: 6 additions & 7 deletions gridstatus/tests/test_isone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ def test_isone_fuel_mix():

def run_all(date):
iso = gridstatus.ISONE()

data = iso.get_fuel_mix(date=date)
data = iso.get_load(date=date)
data = iso.get_load_forecast(date=date)
data = iso.get_lmp(date=date, market=Markets.DAY_AHEAD_HOURLY)
data = iso.get_lmp(date=date, market=Markets.REAL_TIME_5_MIN)
data = iso.get_lmp(date=date, market=Markets.REAL_TIME_HOURLY)
iso.get_fuel_mix(date=date)
iso.get_load(date=date)
iso.get_load_forecast(date=date)
iso.get_lmp(date=date, market=Markets.DAY_AHEAD_HOURLY)
iso.get_lmp(date=date, market=Markets.REAL_TIME_5_MIN)
iso.get_lmp(date=date, market=Markets.REAL_TIME_HOURLY)


def test_isone_dst_end():
Expand Down
14 changes: 6 additions & 8 deletions gridstatus/tests/test_isos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pandas.api.types import is_numeric_dtype

import gridstatus
from gridstatus import *
from gridstatus import CAISO, ISONE, MISO, NYISO, PJM, SPP, Ercot, Markets
from gridstatus.base import FuelMix, GridStatus, ISOBase

all_isos = [MISO(), CAISO(), PJM(), Ercot(), SPP(), NYISO(), ISONE()]
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_get_iso():


def test_get_iso_invalid():
with pytest.raises(Exception) as e_info:
with pytest.raises(Exception):
gridstatus.get_iso("ISO DOESNT EXIST")


Expand Down Expand Up @@ -281,9 +281,7 @@ def test_get_historical_lmp(test):
def test_get_latest_lmp(test):
iso = list(test)[0]
markets = test[iso]["markets"]
locations = test[iso]

date_str = "20220722"
for m in markets:
print(iso.iso_id, m)
latest = iso.get_lmp(date="latest", market=m)
Expand Down Expand Up @@ -421,13 +419,13 @@ def test_date_or_start(iso):
end = pd.Timestamp.now(tz=iso.default_timezone)
start = end - pd.Timedelta(days=num_days)

data_date = iso.get_fuel_mix(date=start.date(), end=end.date())
data_start = iso.get_fuel_mix(
iso.get_fuel_mix(date=start.date(), end=end.date())
iso.get_fuel_mix(
start=start.date(),
end=end.date(),
)
data_date = iso.get_fuel_mix(date=start.date())
data_start = iso.get_fuel_mix(start=start.date())
iso.get_fuel_mix(date=start.date())
iso.get_fuel_mix(start=start.date())

with pytest.raises(ValueError):
iso.get_fuel_mix(start=start.date(), date=start.date())
Expand Down
5 changes: 2 additions & 3 deletions gridstatus/tests/test_nyiso.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pandas as pd
import pytest

import gridstatus
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_location_type_parameter():
assert (df_gen["Location Type"] == "Generator").all()

with pytest.raises(ValueError):
df = iso.get_lmp(
iso.get_lmp(
date="latest",
market=Markets.DAY_AHEAD_HOURLY,
location_type="dummy",
Expand Down Expand Up @@ -166,7 +165,7 @@ def test_nyiso_get_loads():

def test_nyiso_interconnection_queue():
iso = gridstatus.NYISO()
df = iso.get_interconnection_queue()
iso.get_interconnection_queue()


def test_nyiso_get_capacity_prices():
Expand Down
4 changes: 1 addition & 3 deletions gridstatus/tests/test_pjm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from ftplib import ftpcp

import pandas as pd
import pytest

Expand Down Expand Up @@ -30,7 +28,7 @@ def test_no_data():
date = "2000-01-14"
iso = gridstatus.PJM()
with pytest.raises(RuntimeError):
df = iso.get_fuel_mix(start=date)
iso.get_fuel_mix(start=date)


def test_dst_shift_back():
Expand Down
1 change: 0 additions & 1 deletion gridstatus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
GREEN_CHECKMARK_HTML_ENTITY = "&#x2705;"

RED_X_HTML_ENTITY = "&#10060;"

all_isos = [MISO, CAISO, PJM, Ercot, SPP, NYISO, ISONE]


Expand Down