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

Autofix flake8 ignores E711, E712, E714, F401, F841 with Ruff #542

Merged
merged 5 commits into from
Aug 12, 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
22 changes: 9 additions & 13 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@ per-file-ignores =
test_granules.py:E501
# imported but unused
__init__.py:F401
# import not at top of file
doc/source/conf.py:E402
# import not at top of file, imported but unused
doc/source/conf.py:E402,F401

# GOAL: remove these ignores
ignore =
# line too long
# NOTE: This is a formatting concern. Black handles long lines of code, but
# allows inline comments to be infinitely long (automatically formatting
# them can have unintended consequences). In our codebase, we have a lot of
# overlong comments.
# See: https://github.com/psf/black/issues/1713#issuecomment-1357045092
E501
# comparison syntax
E711
# comparison syntax
E712
# comparison syntax in tests
E714
# GOAL: remove ignores below this line
# comparison syntax in tests
E721
# bare except
E722
# ambiguous var name
E741
# imported but unused
F401
# unable to detect undefined names
F403
# assigned and unused (in tests)
F841
# line break before binary operator
# NOTE: This is a formatting concern
W503

# GOAL:
Expand Down
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
repos:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # Use the ref you want to point at
hooks:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # Use the ref you want to point at
hooks:
- id: check-toml
- id: check-yaml
- id: check-added-large-files
args: ["--maxkb=5000"]
- id: end-of-file-fixer
Expand Down
1 change: 0 additions & 1 deletion icepyx/core/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import datetime
import warnings

import earthaccess
from icepyx.core.exceptions import DeprecationError
Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def place_order(
# DevGoal: use the request response/number to do some error handling/
# give the user better messaging for failures
# print(request.content)
root = ET.fromstring(request.content)
# root = ET.fromstring(request.content)
# print([subset_agent.attrib for subset_agent in root.iter('SubsetAgent')])

if verbose is True:
Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/is2ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_varlist(elem):

get_varlist(root)
vars_vals = [
v.replace(":", "/") if v.startswith("/") == False else v.replace("/:", "")
v.replace(":", "/") if v.startswith("/") is False else v.replace("/:", "")
for v in vars_raw
]
cust_options.update({"variables": vars_vals})
Expand Down
13 changes: 7 additions & 6 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import geopandas as gpd
import matplotlib.pyplot as plt
from pathlib import Path # used in docstring tests
JessicaS11 marked this conversation as resolved.
Show resolved Hide resolved
import pprint

import icepyx.core.APIformatting as apifmt
Expand Down Expand Up @@ -103,9 +102,10 @@

Initializing Query with a geospatial polygon file.

>>> aoi = str(Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve())
>>> from pathlib import Path
>>> aoi = Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve()
>>> reg_a_dates = ['2019-02-22','2019-02-28']
>>> reg_a = GenQuery(aoi, reg_a_dates)
>>> reg_a = GenQuery(str(aoi), reg_a_dates)
>>> print(reg_a)
Extent type: polygon
Coordinates: [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0]
Expand Down Expand Up @@ -378,9 +378,10 @@

Initializing Query with a geospatial polygon file.

>>> aoi = str(Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve())
>>> from pathlib import Path
>>> aoi = Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve()
>>> reg_a_dates = ['2019-02-22','2019-02-28']
>>> reg_a = Query('ATL06', aoi, reg_a_dates)
>>> reg_a = Query('ATL06', str(aoi), reg_a_dates)
>>> print(reg_a)
Product ATL06 v006
('polygon', [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0])
Expand Down Expand Up @@ -1132,7 +1133,7 @@
gdf = self._spatial.extent_as_gdf

try:
from shapely.geometry import Polygon
from shapely.geometry import Polygon # noqa: F401

Check warning on line 1136 in icepyx/core/query.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/query.py#L1136

Added line #L1136 was not covered by tests
mfisher87 marked this conversation as resolved.
Show resolved Hide resolved
import geoviews as gv

gv.extension("bokeh")
Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import earthaccess
import numpy as np
from s3fs.core import S3File
mfisher87 marked this conversation as resolved.
Show resolved Hide resolved
import xarray as xr

from icepyx.core.auth import EarthdataAuthMixin
Expand Down Expand Up @@ -634,6 +633,7 @@ def load(self):
) # wanted_groups, vgrp.keys()))

# Closing the file prevents further operations on the dataset
# from s3fs.core import S3File
# if isinstance(file, S3File):
# file.close()

Expand Down
72 changes: 36 additions & 36 deletions icepyx/core/spatial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import geopandas as gpd
import numpy as np
import os
from pathlib import Path
from shapely.geometry import box, Polygon
from shapely.geometry.polygon import orient
import warnings

import icepyx.core.APIformatting as apifmt

# DevGoal: need to update the spatial_extent docstring to describe coordinate order for input

Expand Down Expand Up @@ -62,7 +60,7 @@ def geodataframe(extent_type, spatial_extent, file=False, xdateline=None):
# print("this should cross the dateline:" + str(xdateline))

if extent_type == "bounding_box":
if xdateline == True:
if xdateline is True:
cartesian_lons = [i if i > 0 else i + 360 for i in spatial_extent[0:-1:2]]
cartesian_spatial_extent = [
item
Expand All @@ -79,14 +77,14 @@ def geodataframe(extent_type, spatial_extent, file=False, xdateline=None):
# DevGoal: Currently this if/else within this elif are not tested...
# DevGoal: the crs setting and management needs to be improved

elif extent_type == "polygon" and file == False:
elif extent_type == "polygon" and file is False:
# if spatial_extent is already a Polygon
if isinstance(spatial_extent, Polygon):
spatial_extent_geom = spatial_extent

# else, spatial_extent must be a list of floats (or list of tuples of floats)
else:
if xdateline == True:
if xdateline is True:
cartesian_lons = [
i if i > 0 else i + 360 for i in spatial_extent[0:-1:2]
]
Expand All @@ -109,7 +107,7 @@ def geodataframe(extent_type, spatial_extent, file=False, xdateline=None):

# If extent_type is a polygon AND from a file, create a geopandas geodataframe from it
# DevGoal: Currently this elif isn't tested...
elif extent_type == "polygon" and file == True:
elif extent_type == "polygon" and file is True:
gdf = gpd.read_file(spatial_extent)

else:
Expand Down Expand Up @@ -397,37 +395,38 @@ def __init__(self, spatial_extent, **kwarg):
Optional keyword argument to let user specify whether the spatial input crosses the dateline or not.


See Also
--------
icepyx.Query


Examples
--------
Initializing Spatial with a bounding box.

>>> reg_a_bbox = [-55, 68, -48, 71]
>>> reg_a = Spatial(reg_a_bbox)
>>> print(reg_a)
Extent type: bounding_box
Coordinates: [-55.0, 68.0, -48.0, 71.0]

Initializing Query with a list of polygon vertex coordinate pairs.

>>> reg_a_poly = [(-55, 68), (-55, 71), (-48, 71), (-48, 68), (-55, 68)]
>>> reg_a = Spatial(reg_a_poly)
>>> print(reg_a)
Extent type: polygon
Coordinates: [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0]
See Also
--------
icepyx.Query

Initializing Query with a geospatial polygon file.

>>> aoi = str(Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve())
>>> reg_a = Spatial(aoi)
>>> print(reg_a) # doctest: +SKIP
Extent Type: polygon
Source file: ./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg
Coordinates: [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0]
Examples
--------
Initializing Spatial with a bounding box.

>>> reg_a_bbox = [-55, 68, -48, 71]
>>> reg_a = Spatial(reg_a_bbox)
>>> print(reg_a)
Extent type: bounding_box
Coordinates: [-55.0, 68.0, -48.0, 71.0]

Initializing Query with a list of polygon vertex coordinate pairs.

>>> reg_a_poly = [(-55, 68), (-55, 71), (-48, 71), (-48, 68), (-55, 68)]
>>> reg_a = Spatial(reg_a_poly)
>>> print(reg_a)
Extent type: polygon
Coordinates: [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0]

Initializing Query with a geospatial polygon file.

>>> from pathlib import Path
>>> aoi = Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve()
>>> reg_a = Spatial(str(aoi))
>>> print(reg_a) # doctest: +SKIP
Extent Type: polygon
Source file: ./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg
Coordinates: [-55.0, 68.0, -55.0, 71.0, -48.0, 71.0, -48.0, 68.0, -55.0, 68.0]
"""

scalar_types = (int, float, np.int64)
Expand Down Expand Up @@ -590,6 +589,7 @@ def extent_file(self):
>>> reg_a.extent_file


>>> from pathlib import Path
>>> reg_a = Spatial(str(Path('./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg').resolve()))
>>> reg_a.extent_file # doctest: +SKIP
./doc/source/example_notebooks/supporting_files/simple_test_poly.gpkg
Expand Down Expand Up @@ -643,7 +643,7 @@ def fmt_for_CMR(self):
extent = [float(i) for i in polygon]

# TODO: explore how this will be impacted if the polygon is read in from a shapefile and crosses the dateline
if hasattr(self, "_xdateln") and self._xdateln == True:
if hasattr(self, "_xdateln") and self._xdateln is True:
neg_lons = [i if i < 181.0 else i - 360 for i in extent[0:-1:2]]
extent = [item for pair in zip(neg_lons, extent[1::2]) for item in pair]

Expand Down
3 changes: 0 additions & 3 deletions icepyx/core/validate_inputs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import datetime as dt
import os
import warnings
import numpy as np

import icepyx.core.APIformatting as apifmt


def prod_version(latest_vers, version):
"""
Expand Down
Loading