Skip to content

Commit

Permalink
Fix F401 and F841 lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Aug 8, 2024
1 parent 65e7ee4 commit ff9774e
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 96 deletions.
14 changes: 6 additions & 8 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ per-file-ignores =
doc/source/conf.py:E402

ignore =
# line too long; 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.
# 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
# GOAL: remove ignores below this line
Expand All @@ -25,13 +26,10 @@ ignore =
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
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
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
import pprint

import icepyx.core.APIformatting as apifmt
Expand Down Expand Up @@ -103,9 +102,10 @@ class GenQuery:
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 @@ class Query(GenQuery, EarthdataAuthMixin):
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 @@ def visualize_spatial_extent(
gdf = self._spatial.extent_as_gdf

try:
from shapely.geometry import Polygon
from shapely.geometry import Polygon # noqa: F401
import geoviews as gv

gv.extension("bokeh")
Expand Down
1 change: 0 additions & 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
import xarray as xr

from icepyx.core.auth import EarthdataAuthMixin
Expand Down
62 changes: 31 additions & 31 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 @@ -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
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
2 changes: 0 additions & 2 deletions icepyx/core/variables.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy as np
import os
import pprint

from icepyx.core.auth import EarthdataAuthMixin
import icepyx.core.is2ref as is2ref
from icepyx.core.exceptions import DeprecationError
import icepyx.core.validate_inputs as val
import icepyx.core as ipxc

# DEVGOAL: use h5py to simplify some of these tasks, if possible!

Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def request_OA_data(self, paras) -> da.array:
df_series = df.query(expr="date == @Date").iloc[0]
beam_data = df_series.beams

except (NameError, KeyError, IndexError) as error:
except (NameError, KeyError, IndexError):
beam_data = None

if not beam_data:
Expand Down
2 changes: 0 additions & 2 deletions icepyx/quest/quest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import matplotlib.pyplot as plt

from icepyx.core.query import GenQuery, Query

from icepyx.quest.dataset_scripts.argo import Argo
Expand Down
2 changes: 0 additions & 2 deletions icepyx/tests/is2class_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import icepyx as ipx
import pytest
import warnings


def test_CMRparams():
Expand Down
1 change: 0 additions & 1 deletion icepyx/tests/test_Earthdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import pytest
import shutil
import warnings


# PURPOSE: test different authentication methods
Expand Down
1 change: 0 additions & 1 deletion icepyx/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import earthaccess

from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.exceptions import DeprecationError


@pytest.fixture()
Expand Down
1 change: 0 additions & 1 deletion icepyx/tests/test_quest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import re

import icepyx as ipx
from icepyx.quest.quest import Quest
Expand Down
41 changes: 18 additions & 23 deletions icepyx/tests/test_spatial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import datetime as dt
import geopandas as gpd
import numpy as np
import os
from pathlib import Path
import pytest
import re
from shapely.geometry import Polygon
import warnings

import icepyx.core.spatial as spat

Expand Down Expand Up @@ -65,62 +62,62 @@ def test_intlist_with0_bbox():

def test_too_few_bbox_points():
with pytest.raises(AssertionError):
too_few_bbox_points = spat.Spatial([-64.2, 66.2, -55.5])
spat.Spatial([-64.2, 66.2, -55.5])


def test_too_many_bbox_points():
with pytest.raises(AssertionError):
too_many_bbox_points = spat.Spatial([-64.2, 66.2, -55.5, 72.5, 0])
spat.Spatial([-64.2, 66.2, -55.5, 72.5, 0])


def test_invalid_low_latitude_1_bbox():
with pytest.raises(AssertionError):
low_lat_1_bbox = spat.Spatial([-64.2, -90.2, -55.5, 72.5])
spat.Spatial([-64.2, -90.2, -55.5, 72.5])


def test_invalid_high_latitude_1_bbox():
with pytest.raises(AssertionError):
high_lat_1_bbox = spat.Spatial([-64.2, 90.2, -55.5, 72.5])
spat.Spatial([-64.2, 90.2, -55.5, 72.5])


def test_invalid_low_latitude_3_bbox():
with pytest.raises(AssertionError):
low_lat_3_bbox = spat.Spatial([-64.2, 66.2, -55.5, -90.5])
spat.Spatial([-64.2, 66.2, -55.5, -90.5])


def test_invalid_high_latitude_3_bbox():
with pytest.raises(AssertionError):
high_lat_3_bbox = spat.Spatial([-64.2, 66.2, -55.5, 90.5])
spat.Spatial([-64.2, 66.2, -55.5, 90.5])


def test_invalid_low_longitude_0_bbox():
with pytest.raises(AssertionError):
low_lon_0_bbox = spat.Spatial([-180.2, 66.2, -55.5, 72.5])
spat.Spatial([-180.2, 66.2, -55.5, 72.5])


def test_invalid_high_longitude_0_bbox():
with pytest.raises(AssertionError):
high_lon_0_bbox = spat.Spatial([180.2, 66.2, -55.5, 72.5])
spat.Spatial([180.2, 66.2, -55.5, 72.5])


def test_invalid_low_longitude_2_bbox():
with pytest.raises(AssertionError):
low_lon_2_bbox = spat.Spatial([-64.2, 66.2, -180.5, 72.5])
spat.Spatial([-64.2, 66.2, -180.5, 72.5])


def test_invalid_high_longitude_2_bbox():
with pytest.raises(AssertionError):
high_lon_2_bbox = spat.Spatial([-64.2, 66.2, 180.5, 72.5])
spat.Spatial([-64.2, 66.2, 180.5, 72.5])


def test_same_sign_lowleft_gt_upright_latitude_bbox():
with pytest.raises(AssertionError):
lat_ll_gt_ur_ss_bbox = spat.Spatial([-64.2, 72.5, -55.5, 66.2])
spat.Spatial([-64.2, 72.5, -55.5, 66.2])


def test_bad_values_bbox():
with pytest.raises(ValueError):
bad_input = spat.Spatial(["a", "b", "c", "d"])
spat.Spatial(["a", "b", "c", "d"])


# ############### END BOUNDING BOX TESTS ################################################################
Expand Down Expand Up @@ -287,19 +284,17 @@ def test_numpy_intlist_latlon_coords():

def test_odd_num_lat_long_list_poly_throws_error():
with pytest.raises(AssertionError):
bad_input = spat.Spatial([-55, 68, -55, 71, -48, 71, -48, 68, -55])
spat.Spatial([-55, 68, -55, 71, -48, 71, -48, 68, -55])


def test_wrong_num_lat_long_tuple_poly_throws_error():
with pytest.raises(ValueError):
bad_input = spat.Spatial(
[(-55, 68, 69), (-55, 71), (-48, 71), (-48, 68), (-55, 68)]
)
spat.Spatial([(-55, 68, 69), (-55, 71), (-48, 71), (-48, 68), (-55, 68)])


def test_bad_value_types_poly():
with pytest.raises(ValueError):
bad_input = spat.Spatial(["a", "b", "c", "d", "e"])
spat.Spatial(["a", "b", "c", "d", "e"])


# ###################### Automatically Closed Polygon Tests ###########################################################
Expand Down Expand Up @@ -378,12 +373,12 @@ def test_poly_file_simple_one_poly():

def test_bad_poly_inputfile_name_throws_error():
with pytest.raises(AssertionError):
bad_input = spat.Spatial("bad_filename.gpkg")
spat.Spatial("bad_filename.gpkg")


def test_bad_poly_inputfile_type_throws_error():
with pytest.raises(TypeError):
bad_input = spat.Spatial(str(Path("./icepyx/tests/test_read.py").resolve()))
spat.Spatial(str(Path("./icepyx/tests/test_read.py").resolve()))


########## geodataframe ##########
Expand Down Expand Up @@ -461,7 +456,7 @@ def test_bbox_not_crosses_dateline(bbox):

def test_poly_wrong_input():
with pytest.raises(AssertionError):
tuplelist = spat.check_dateline(
spat.check_dateline(
"polygon",
[[160, -45], [160, -40], [-170, -39], [-128, -40], [-128, -45], [160, -45]],
)
Expand Down
Loading

0 comments on commit ff9774e

Please sign in to comment.