Skip to content

Commit

Permalink
💬 Update type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
arafune committed Mar 19, 2024
1 parent 330ac67 commit ab4b0f5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
12 changes: 12 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ Self-Energy
analysis.self_energy.quasiparticle_lifetime


Time-Resolved ARPES Related
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::

analysis.tarpes.find_t0
analysis.tarpes.relative_change
analysis.tarpes.normalized_relative_change
analysis.tarpes.build_crosscorrelation
analysis.tarpes.delaytime_fs
analysis.tarpes.position_to_delaytime


Spin-ARPES Related
~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ lint.ignore = [
"NPY201", # Numpy 2.0,
]
lint.select = ["ALL"]
target-version = "py310"
target-version = "py311"
line-length = 100
indent-width = 4

Expand Down
2 changes: 1 addition & 1 deletion src/arpes/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ConfigSettings(TypedDict, total=False):
class WorkSpaceType(TypedDict, total=False):
"""TypedDict for arpes.config.CONFIG["WORKSPACE"]."""

path: str | Path
path: Required[str | Path]
name: str


Expand Down
6 changes: 3 additions & 3 deletions src/arpes/analysis/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def polys_to_mask(
radius: float = 0,
*,
invert: bool = False,
) -> NDArray[np.float_] | NDArray[np.bool_]:
) -> NDArray[np.bool_]:
"""Converts a mask definition in terms of the underlying polygon to a True/False mask array.
Uses the coordinates and shape of the target data in order to determine which pixels
Expand All @@ -70,7 +70,7 @@ def polys_to_mask(
coords:
shape:
radius (float): Additional margin on the path in coordinates of *points*.
invert (bool):
invert (bool): if true, flip True/False in mask.
Returns:
The mask.
Expand Down Expand Up @@ -108,7 +108,7 @@ def apply_mask_to_coords(
dims: list[str],
*,
invert: bool = True,
):
) -> NDArray[np.bool_]:
"""Performs broadcasted masking along a given dimension.
Args:
Expand Down
10 changes: 5 additions & 5 deletions src/arpes/utilities/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
)


T = TypeVar("T")


def _rename_key(
d: dict[str, Any],
original_name_k: str,
Expand All @@ -27,9 +30,9 @@ def _rename_key(


def rename_keys(
d: dict[str, Any],
d: dict[str, T],
keys_dict: dict[str, str],
) -> dict[str, Any]:
) -> dict[str, T]:
"""Renames all the keys of `d` according to the remapping in `keys_dict`.
Args:
Expand All @@ -46,9 +49,6 @@ def rename_keys(
return d


T = TypeVar("T")


def clean_keys(d: dict[str, T]) -> dict[str, T]:
"""Renames dict key to fit Pythonic more.
Expand Down
8 changes: 5 additions & 3 deletions src/arpes/utilities/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from logging import DEBUG, INFO, Formatter, StreamHandler, getLogger
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, TypeVar

import xarray as xr

Expand Down Expand Up @@ -38,6 +38,8 @@
logger.addHandler(handler)
logger.propagate = False

T = TypeVar("T")


def unwrap_xarray_item(item: xr.DataArray) -> xr.DataArray | float:
"""Unwraps something that might or might not be an xarray like with .item() attribute.
Expand Down Expand Up @@ -115,7 +117,7 @@ def g(arr: xr.DataArray, *args: Incomplete, **kwargs: Incomplete) -> xr.DataArra


def lift_dataarray_attrs(
f: Callable[[dict[str, Any], Any], dict[str, Any]],
f: Callable[[dict[str, T], Any], dict[str, T]] | Callable[[dict[str, T]], dict[str, T]],
) -> Callable[[xr.DataArray], xr.DataArray]:
"""Lifts a function that operates dicts to a function that acts on dataarray attrs.
Expand Down Expand Up @@ -154,7 +156,7 @@ def g(


def lift_datavar_attrs(
f: Callable[[dict[str, Any], Any], dict[str, Any]],
f: Callable[[dict[str, T], Any], dict[str, T]] | Callable[[dict[str, T]], dict[str, T]],
) -> Callable[..., DataType]:
"""Lifts a function that operates dicts to a function that acts on xr attrs.
Expand Down

0 comments on commit ab4b0f5

Please sign in to comment.