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

Remove future annotations import and style because it's deprecated #10

Merged
merged 2 commits into from
Dec 6, 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
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import importlib.metadata

project = "pyia"
Expand Down
2 changes: 0 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import argparse
import shutil
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ disallow_incomplete_defs = false
module = "pyia.*"
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = false

[[tool.mypy.overrides]]
module = [
Expand Down Expand Up @@ -152,7 +153,6 @@ ignore = [
"PLR2004", # Magic value used in comparison
"ISC001", # Conflicts with formatter
]
isort.required-imports = ["from __future__ import annotations"]
# Uncomment if using a _compat.typing backport
# typing-modules = ["pyia._compat.typing"]

Expand Down
2 changes: 0 additions & 2 deletions src/pyia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"""


from __future__ import annotations

from . import data
from ._version import version as __version__
from .data import GaiaData
Expand Down
2 changes: 0 additions & 2 deletions src/pyia/_version.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from __future__ import annotations

version: str
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str]
53 changes: 26 additions & 27 deletions src/pyia/data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
""" Data structures. """

# Standard library
from __future__ import annotations

import pathlib
from typing import Any
from typing import Any, Dict, List, Optional, Tuple, Union

# Third-party
import astropy.coordinates as coord
Expand Down Expand Up @@ -104,7 +102,7 @@ class GaiaData:
"""

def __init__(
self, data: Table | str | pathlib.Path | dict[str, Any], **kwargs: Any
self, data: Union[Table, str, pathlib.Path, Dict[str, Any]], **kwargs: Any
) -> None:
if not isinstance(data, Table):
if isinstance(data, (str, pathlib.Path)):
Expand Down Expand Up @@ -149,15 +147,15 @@ def __init__(
)

# For caching later
self._cache: dict[Any, Any] = {}
self._cache: Dict[Any, Any] = {}

@classmethod
def from_query(
cls,
query_str: str,
login_info: dict[str, str] | None = None,
login_info: Optional[Dict[str, str]] = None,
verbose: bool = False,
) -> GaiaData:
) -> "GaiaData":
"""
Run the specified query and return a `GaiaData` instance with the
returned data.
Expand Down Expand Up @@ -205,10 +203,10 @@ def from_query(
def from_source_id(
cls,
source_id: int,
source_id_dr: str | None = None,
data_dr: str | None = None,
source_id_dr: Optional[str] = None,
data_dr: Optional[str] = None,
**kwargs: Any,
) -> GaiaData:
) -> "GaiaData":
"""Retrieve data from a DR for a given Gaia source_id in a DR.

Useful if you have, e.g., a DR2 source_id and want EDR3 data.
Expand Down Expand Up @@ -272,7 +270,7 @@ def from_source_id(
##########################################################################
# Python internal
#
def __getattr__(self, name: Any) -> npt.NDArray | u.Quantity:
def __getattr__(self, name: Any) -> Union[npt.NDArray, u.Quantity]:
# to prevent recursion errors:
# nedbatchelder.com/blog/201010/surprising_getattr_recursion.html
if name in ["data", "units"]:
Expand Down Expand Up @@ -321,10 +319,12 @@ def __setattr__(self, name: Any, val: Any) -> None:
else:
super().__setattr__(name, val)

def __dir__(self) -> list[str]:
def __dir__(self) -> List[str]:
return list(super().__dir__()) + [str(k) for k in self.data.columns]

def __getitem__(self, slc: int | slice | npt.NDArray) -> GaiaData | Any:
def __getitem__(
self, slc: Union[int, slice, npt.NDArray]
) -> Union["GaiaData", Any]:
if isinstance(slc, int):
slc = slice(slc, slc + 1)
elif isinstance(slc, str):
Expand Down Expand Up @@ -354,7 +354,7 @@ def __repr__(self) -> str:
# Computed and convenience quantities
#
def get_pm(
self, frame: str | coord.BaseCoordinateFrame = "icrs"
self, frame: Union[str, coord.BaseCoordinateFrame] = "icrs"
) -> u.Quantity[u.mas / u.yr]:
"""Get the 2D proper motion array in the specified frame

Expand All @@ -377,11 +377,10 @@ def get_pm(
)
return pm

# TODO: re-enable this when Astropy adds support for __future__ annotations
# @u.quantity_input(equivalencies=u.parallax())
@u.quantity_input # (equivalencies=u.parallax())
def get_distance(
self,
min_parallax: u.Quantity[angle] | None = None,
min_parallax: Optional[u.Quantity[angle]] = None,
parallax_fill_value: float = np.nan,
allow_negative: bool = False,
) -> u.Quantity[u.kpc]:
Expand Down Expand Up @@ -429,7 +428,7 @@ def distmod(self) -> u.Quantity:
return self.distance.distmod

def get_radial_velocity(
self, fill_value: float | None = None
self, fill_value: Optional[float] = None
) -> u.Quantity[u.km / u.s]:
"""Return radial velocity but with invalid values filled with the
specified fill value.
Expand Down Expand Up @@ -457,8 +456,8 @@ def vtan(self) -> u.Quantity[u.km / u.s]:
def get_cov(
self,
RAM_threshold: u.Quantity = 1 * u.gigabyte,
units: dict[str, u.Unit] | None = None,
) -> tuple[npt.NDArray, dict[str, u.Unit]]:
units: Optional[Dict[str, u.Unit]] = None,
) -> Tuple[npt.NDArray, Dict[str, u.Unit]]:
"""The Gaia data tables contain correlation coefficients and standard
deviations for (ra, dec, parallax, pm_ra, pm_dec), but for most analyses we need
covariance matrices. This converts the data provided by Gaia into covariance
Expand Down Expand Up @@ -542,7 +541,7 @@ def get_cov(

return C, units

def get_ebv(self, dustmaps_cls: Any | None = None) -> npt.NDArray:
def get_ebv(self, dustmaps_cls: Optional[Any] = None) -> npt.NDArray:
"""Compute the E(B-V) reddening at this location

This requires the `dustmaps <http://dustmaps.readthedocs.io>`_ package
Expand All @@ -562,7 +561,7 @@ def get_ebv(self, dustmaps_cls: Any | None = None) -> npt.NDArray:
return dustmaps_cls().query(c)

def get_ext(
self, ebv: npt.ArrayLike | None = None, dustmaps_cls: Any | None = None
self, ebv: Optional[npt.ArrayLike] = None, dustmaps_cls: Optional[Any] = None
) -> npt.NDArray:
"""Compute the E(B-V) reddening at this location

Expand Down Expand Up @@ -649,8 +648,8 @@ def skycoord(self) -> coord.SkyCoord:

def get_skycoord(
self,
distance: u.Quantity[length] | None = None,
radial_velocity: u.Quantity[vel] | None = None,
distance: Optional[u.Quantity[length]] = None,
radial_velocity: Optional[u.Quantity[vel]] = None,
ref_epoch: str = REF_EPOCH[LATEST_RELEASE],
) -> coord.SkyCoord:
"""
Expand Down Expand Up @@ -730,8 +729,8 @@ def get_skycoord(
def get_error_samples(
self,
size: int = 1,
rng: int | np.random.Generator | None = None,
) -> GaiaData:
rng: Union[int, np.random.Generator, None] = None,
) -> "GaiaData":
"""Generate a sampling from the Gaia error distribution for each source.

This function constructs the astrometric covariance matrix for each source and
Expand Down Expand Up @@ -780,7 +779,7 @@ def get_error_samples(

return self.__class__(d)

def filter(self, **kwargs: Any) -> GaiaData:
def filter(self, **kwargs: Any) -> "GaiaData":
"""
Filter the data based on columns and data ranges.

Expand Down
6 changes: 3 additions & 3 deletions src/pyia/extinction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ruff: noqa

# Third-party
from __future__ import annotations
from typing import Tuple

# Third-party
import numpy as np
import numpy.typing as npt

Expand All @@ -16,7 +16,7 @@ def get_ext_dr2_Babusiaux(
rp: npt.ArrayLike,
ebv: npt.ArrayLike,
maxnit: int = 8,
) -> tuple[npt.NDArray, npt.NDArray, npt.NDArray]:
) -> Tuple[npt.NDArray, npt.NDArray, npt.NDArray]:
"""Compute the Gaia extinctions assuming relations from Babusieux+2018
Arguments: G, bp, rp, E(B-V)
maxnit -- number of iterations
Expand Down
4 changes: 2 additions & 2 deletions src/pyia/setup_package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Dict, List


def get_package_data() -> dict[str, list[str]]:
def get_package_data() -> Dict[str, List[str]]:
return {"pyia": ["data/*"]}
2 changes: 0 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Standard library
from __future__ import annotations

import pathlib
import warnings

Expand Down