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

Promote pandas to a required dependency #1586

Merged
merged 3 commits into from
Sep 25, 2023
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ dependencies = [
"matplotlib>=3.3.3",
# numpy 1.19.3+ required by Python 3.9 wheels
"numpy>=1.19.3",
# pandas 1.1.3+ required for Python 3.9 wheels
"pandas>=1.1.3",
# pillow 8+ required for Python 3.9 wheels
"pillow>=8",
# pyproj 3+ required for Python 3.9 wheels
Expand Down Expand Up @@ -82,8 +84,6 @@ datasets = [
"laspy>=2",
# opencv-python 4.4.0.46+ required for Python 3.9 wheels
"opencv-python>=4.4.0.46",
# pandas 1.1.3+ required for Python 3.9 wheels
"pandas>=1.1.3",
# pycocotools 2.0.5+ required for cython 3+ support
"pycocotools>=2.0.5",
# pyvista 0.29+ required for to avoid segfault during testing
Expand Down
1 change: 0 additions & 1 deletion requirements/datasets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
h5py==3.9.0
laspy==2.5.1
opencv-python==4.8.0.76
pandas==2.1.1
pycocotools==2.0.7
pyvista==0.42.2
radiant-mlhub==0.4.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/min-reqs.old
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lightly==1.4.4
lightning==1.8.0
matplotlib==3.3.3
numpy==1.19.3
pandas==1.1.3
pillow==8.0.0
pyproj==3.0.0
rasterio==1.2.0
Expand All @@ -24,7 +25,6 @@ torchvision==0.13.0
h5py==3.0.0
laspy==2.0.0
opencv-python==4.4.0.46
pandas==1.1.3
pycocotools==2.0.5
pyvista==0.29.0
radiant-mlhub==0.3.0
Expand Down
1 change: 1 addition & 0 deletions requirements/required.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lightly==1.4.19
lightning==2.0.9
matplotlib==3.8.0
numpy==1.26.0
pandas==2.1.1
pillow==10.0.1
pyproj==3.6.1
rasterio==1.3.8
Expand Down
25 changes: 0 additions & 25 deletions tests/datasets/test_eddmaps.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import os
from pathlib import Path
from typing import Any

import pytest
from pytest import MonkeyPatch

from torchgeo.datasets import BoundingBox, EDDMapS, IntersectionDataset, UnionDataset

pytest.importorskip("pandas", minversion="1.1.3")


class TestEDDMapS:
@pytest.fixture(scope="class")
Expand All @@ -39,26 +34,6 @@ def test_no_data(self, tmp_path: Path) -> None:
with pytest.raises(FileNotFoundError, match="Dataset not found"):
EDDMapS(str(tmp_path))

@pytest.fixture
def mock_missing_module(self, monkeypatch: MonkeyPatch) -> None:
import_orig = builtins.__import__

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == "pandas":
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)

def test_mock_missing_module(
self, dataset: EDDMapS, mock_missing_module: None
) -> None:
with pytest.raises(
ImportError,
match="pandas is not installed and is required to use this dataset",
):
EDDMapS(dataset.root)

def test_invalid_query(self, dataset: EDDMapS) -> None:
query = BoundingBox(0, 0, 0, 0, 0, 0)
with pytest.raises(
Expand Down
25 changes: 0 additions & 25 deletions tests/datasets/test_gbif.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import os
from pathlib import Path
from typing import Any

import pytest
from pytest import MonkeyPatch

from torchgeo.datasets import GBIF, BoundingBox, IntersectionDataset, UnionDataset

pytest.importorskip("pandas", minversion="1.1.3")


class TestGBIF:
@pytest.fixture(scope="class")
Expand All @@ -39,26 +34,6 @@ def test_no_data(self, tmp_path: Path) -> None:
with pytest.raises(FileNotFoundError, match="Dataset not found"):
GBIF(str(tmp_path))

@pytest.fixture
def mock_missing_module(self, monkeypatch: MonkeyPatch) -> None:
import_orig = builtins.__import__

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == "pandas":
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)

def test_mock_missing_module(
self, dataset: GBIF, mock_missing_module: None
) -> None:
with pytest.raises(
ImportError,
match="pandas is not installed and is required to use this dataset",
):
GBIF(dataset.root)

def test_invalid_query(self, dataset: GBIF) -> None:
query = BoundingBox(0, 0, 0, 0, 0, 0)
with pytest.raises(
Expand Down
7 changes: 3 additions & 4 deletions tests/datasets/test_idtrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import torchgeo.datasets.utils
from torchgeo.datasets import IDTReeS

pytest.importorskip("pandas", minversion="1.1.3")
pytest.importorskip("laspy", minversion="2")


Expand Down Expand Up @@ -51,7 +50,7 @@ def dataset(
transforms = nn.Identity()
return IDTReeS(root, split, task, transforms, download=True, checksum=True)

@pytest.fixture(params=["pandas", "laspy", "pyvista"])
@pytest.fixture(params=["laspy", "pyvista"])
def mock_missing_module(self, monkeypatch: MonkeyPatch, request: SubRequest) -> str:
import_orig = builtins.__import__
package = str(request.param)
Expand Down Expand Up @@ -110,13 +109,13 @@ def test_mock_missing_module(
) -> None:
package = mock_missing_module

if package in ["pandas", "laspy"]:
if package == "laspy":
with pytest.raises(
ImportError,
match=f"{package} is not installed and is required to use this dataset",
):
IDTReeS(dataset.root, dataset.split, dataset.task)
elif package in ["pyvista"]:
elif package == "pyvista":
with pytest.raises(
ImportError,
match=f"{package} is not installed and is required to plot point cloud",
Expand Down
25 changes: 0 additions & 25 deletions tests/datasets/test_inaturalist.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import os
from pathlib import Path
from typing import Any

import pytest
from pytest import MonkeyPatch

from torchgeo.datasets import (
BoundingBox,
Expand All @@ -16,8 +13,6 @@
UnionDataset,
)

pytest.importorskip("pandas", minversion="1.1.3")


class TestINaturalist:
@pytest.fixture(scope="class")
Expand All @@ -44,26 +39,6 @@ def test_no_data(self, tmp_path: Path) -> None:
with pytest.raises(FileNotFoundError, match="Dataset not found"):
INaturalist(str(tmp_path))

@pytest.fixture
def mock_missing_module(self, monkeypatch: MonkeyPatch) -> None:
import_orig = builtins.__import__

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == "pandas":
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)

def test_mock_missing_module(
self, dataset: INaturalist, mock_missing_module: None
) -> None:
with pytest.raises(
ImportError,
match="pandas is not installed and is required to use this dataset",
):
INaturalist(dataset.root)

def test_invalid_query(self, dataset: INaturalist) -> None:
query = BoundingBox(0, 0, 0, 0, 0, 0)
with pytest.raises(
Expand Down
30 changes: 1 addition & 29 deletions tests/datasets/test_openbuildings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import json
import os
import shutil
from pathlib import Path
from typing import Any

import matplotlib.pyplot as plt
import pandas as pd
import pytest
import torch
import torch.nn as nn
from _pytest.fixtures import SubRequest
from pytest import MonkeyPatch
from rasterio.crs import CRS

Expand All @@ -23,8 +21,6 @@
UnionDataset,
)

pd = pytest.importorskip("pandas", minversion="1.1.3")


class TestOpenBuildings:
@pytest.fixture
Expand All @@ -43,30 +39,6 @@ def dataset(self, monkeypatch: MonkeyPatch, tmp_path: Path) -> OpenBuildings:
transforms = nn.Identity()
return OpenBuildings(root=root, transforms=transforms)

@pytest.fixture(params=["pandas"])
def mock_missing_module(self, monkeypatch: MonkeyPatch, request: SubRequest) -> str:
import_orig = builtins.__import__
package = str(request.param)

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == package:
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)
return package

def test_mock_missing_module(
self, dataset: OpenBuildings, mock_missing_module: str
) -> None:
package = mock_missing_module

with pytest.raises(
ImportError,
match=f"{package} is not installed and is required to use this dataset",
):
OpenBuildings(root=dataset.root)

def test_no_shapes_to_rasterize(
self, dataset: OpenBuildings, tmp_path: Path
) -> None:
Expand Down
25 changes: 0 additions & 25 deletions tests/datasets/test_reforestree.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import os
import shutil
from pathlib import Path
from typing import Any

import matplotlib.pyplot as plt
import pytest
Expand All @@ -24,7 +22,6 @@ def download_url(url: str, root: str, *args: str) -> None:
class TestReforesTree:
@pytest.fixture
def dataset(self, monkeypatch: MonkeyPatch, tmp_path: Path) -> ReforesTree:
pytest.importorskip("pandas", minversion="1.1.3")
monkeypatch.setattr(torchgeo.datasets.utils, "download_url", download_url)
data_dir = os.path.join("tests", "data", "reforestree")

Expand Down Expand Up @@ -54,32 +51,10 @@ def test_getitem(self, dataset: ReforesTree) -> None:
assert x["image"].ndim == 3
assert len(x["boxes"]) == 2

@pytest.fixture
def mock_missing_module(self, monkeypatch: MonkeyPatch) -> None:
import_orig = builtins.__import__
package = "pandas"

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == package:
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)

def test_mock_missing_module(
self, dataset: ReforesTree, mock_missing_module: None
) -> None:
with pytest.raises(
ImportError,
match="pandas is not installed and is required to use this dataset",
):
ReforesTree(root=dataset.root)

def test_len(self, dataset: ReforesTree) -> None:
assert len(dataset) == 2

def test_not_extracted(self, tmp_path: Path) -> None:
pytest.importorskip("pandas", minversion="1.1.3")
url = os.path.join("tests", "data", "reforestree", "reforesTree.zip")
shutil.copy(url, tmp_path)
ReforesTree(root=str(tmp_path))
Expand Down
23 changes: 0 additions & 23 deletions tests/datasets/test_seasonet.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import builtins
import glob
import os
import shutil
from pathlib import Path
from typing import Any

import matplotlib.pyplot as plt
import pytest
Expand All @@ -19,8 +17,6 @@
import torchgeo.datasets.utils
from torchgeo.datasets import SeasoNet

pytest.importorskip("pandas", minversion="1.1.3")


def download_url(url: str, root: str, md5: str, *args: str, **kwargs: str) -> None:
shutil.copy(url, root)
Expand Down Expand Up @@ -154,25 +150,6 @@ def test_not_downloaded(self, tmp_path: Path) -> None:
with pytest.raises(RuntimeError, match="not found in"):
SeasoNet(str(tmp_path), download=False)

@pytest.fixture
def mock_missing_module(self, monkeypatch: MonkeyPatch) -> None:
import_orig = builtins.__import__

def mocked_import(name: str, *args: Any, **kwargs: Any) -> Any:
if name == "pandas":
raise ImportError()
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)

def test_mock_missing_module(
self, dataset: SeasoNet, mock_missing_module: None
) -> None:
with pytest.raises(
ImportError, match="pandas is not installed and is required"
):
SeasoNet(dataset.root)

def test_out_of_bounds(self, dataset: SeasoNet) -> None:
with pytest.raises(IndexError):
dataset[5]
Expand Down
Loading