Skip to content

set min version py3.10, cleanup type annotations #465

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

Merged
merged 1 commit into from
Mar 31, 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
18 changes: 9 additions & 9 deletions fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import *
from typing import Any, Literal
import weakref
from warnings import warn
from abc import ABC, abstractmethod
Expand All @@ -13,7 +13,7 @@

# dict that holds all world objects for a given python kernel/session
# Graphic objects only use proxies to WorldObjects
WORLD_OBJECTS: Dict[str, WorldObject] = dict() #: {hex id str: WorldObject}
WORLD_OBJECTS: dict[str, WorldObject] = dict() #: {hex id str: WorldObject}


PYGFX_EVENTS = [
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(
self._plot_area = None

@property
def name(self) -> Union[str, None]:
def name(self) -> str | None:
"""str name reference for this item"""
return self._name

Expand Down Expand Up @@ -162,7 +162,7 @@ def visible(self, v: bool):
self.world_object.visible = v

@property
def children(self) -> List[WorldObject]:
def children(self) -> list[WorldObject]:
"""Return the children of the WorldObject."""
return self.world_object.children

Expand Down Expand Up @@ -432,15 +432,15 @@ class PreviouslyModifiedData:
indices: Any


COLLECTION_GRAPHICS: Dict[str, Graphic] = dict()
COLLECTION_GRAPHICS: dict[str, Graphic] = dict()


class GraphicCollection(Graphic):
"""Graphic Collection base class"""

def __init__(self, name: str = None):
super().__init__(name)
self._graphics: List[str] = list()
self._graphics: list[str] = list()

self._graphics_changed: bool = True
self._graphics_array: np.ndarray[Graphic] = None
Expand Down Expand Up @@ -548,7 +548,7 @@ class CollectionIndexer:
def __init__(
self,
parent: GraphicCollection,
selection: List[Graphic],
selection: list[Graphic],
):
"""

Expand Down Expand Up @@ -605,7 +605,7 @@ def __repr__(self):
class CollectionFeature:
"""Collection Feature"""

def __init__(self, selection: List[Graphic], feature: str):
def __init__(self, selection: list[Graphic], feature: str):
"""
selection: list of Graphics
a list of the selected Graphics from the parent GraphicCollection based on the ``selection_indices``
Expand All @@ -618,7 +618,7 @@ def __init__(self, selection: List[Graphic], feature: str):
self._selection = selection
self._feature = feature

self._feature_instances: List[GraphicFeature] = list()
self._feature_instances: list[GraphicFeature] = list()

if len(self._selection) > 0:
for graphic in self._selection:
Expand Down
6 changes: 3 additions & 3 deletions fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def __init__(
self,
data: Any,
thickness: float = 2.0,
colors: Union[str, np.ndarray, Iterable] = "w",
colors: str | np.ndarray | Iterable = "w",
alpha: float = 1.0,
cmap: str = None,
cmap_values: Union[np.ndarray, List] = None,
cmap_values: np.ndarray | Iterable = None,
z_position: float = None,
collection_index: int = None,
*args,
Expand All @@ -46,7 +46,7 @@ def __init__(
apply a colormap to the line instead of assigning colors manually, this
overrides any argument passed to "colors"

cmap_values: 1D array-like or list of numerical values, optional
cmap_values: 1D array-like or Iterable of numerical values, optional
if provided, these values are used to map the colors from the cmap

alpha: float, optional, default 1.0
Expand Down
77 changes: 43 additions & 34 deletions fastplotlib/graphics/line_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class LineCollection(GraphicCollection, Interaction):
def __init__(
self,
data: List[np.ndarray],
z_position: Union[List[float], float] = None,
thickness: Union[float, List[float]] = 2.0,
colors: Union[List[np.ndarray], np.ndarray] = "w",
z_position: Iterable[float] | float = None,
thickness: float | Iterable[float] = 2.0,
colors: str | Iterable[str] | np.ndarray | Iterable[np.ndarray] = "w",
alpha: float = 1.0,
cmap: Union[List[str], str] = None,
cmap_values: Union[np.ndarray, List] = None,
cmap: Iterable[str] | str = None,
cmap_values: np.ndarray | List = None,
name: str = None,
metadata: Union[list, tuple, np.ndarray] = None,
metadata: Iterable[Any] | np.ndarray = None,
*args,
**kwargs,
):
Expand All @@ -36,39 +36,41 @@ def __init__(

Parameters
----------

data: list of array-like or array
List of line data to plot, each element must be a 1D, 2D, or 3D numpy array
if elements are 2D, interpreted as [y_vals, n_lines]

z_position: list of float or float, optional
z_position: Iterable of float or float, optional
| if ``float``, single position will be used for all lines
| if ``list`` of ``float``, each value will apply to the individual lines

thickness: float or list of float, default 2.0
thickness: float or Iterable of float, default 2.0
| if ``float``, single thickness will be used for all lines
| if ``list`` of ``float``, each value will apply to the individual lines

colors: str, RGBA array, list of RGBA array, or list of str, default "w"
colors: str, RGBA array, Iterable of RGBA array, or Iterable of str, default "w"
| if single ``str`` such as "w", "r", "b", etc, represents a single color for all lines
| if single ``RGBA array`` (tuple or list of size 4), represents a single color for all lines
| if ``list`` of ``str``, represents color for each individual line, example ["w", "b", "r",...]
| if ``RGBA array`` of shape [data_size, 4], represents a single RGBA array for each line

cmap: list of str or str, optional
alpha: float, optional
alpha value for colors, if colors is a ``str``

cmap: Iterable of str or str, optional
| if ``str``, single cmap will be used for all lines
| if ``list`` of ``str``, each cmap will apply to the individual lines

.. note::
``cmap`` overrides any arguments passed to ``colors``

cmap_values: 1D array-like or list of numerical values, optional
cmap_values: 1D array-like or Iterable of numerical values, optional
if provided, these values are used to map the colors from the cmap

name: str, optional
name of the line collection

metadata: list, tuple, or array
metadata: Iterable or array
metadata associated with this collection, this is for the user to manage.
``len(metadata)`` must be same as ``len(data)``

Expand Down Expand Up @@ -235,7 +237,7 @@ def cmap_values(self) -> np.ndarray:
return self._cmap_values

@cmap_values.setter
def cmap_values(self, values: Union[np.ndarray, list]):
def cmap_values(self, values: np.ndarray | Iterable):
colors = parse_cmap_values(
n_colors=len(self), cmap_name=self.cmap, cmap_values=values
)
Expand Down Expand Up @@ -477,13 +479,16 @@ class LineStack(LineCollection):
def __init__(
self,
data: List[np.ndarray],
z_position: Union[List[float], float] = None,
thickness: Union[float, List[float]] = 2.0,
colors: Union[List[np.ndarray], np.ndarray] = "w",
cmap: Union[List[str], str] = None,
separation: float = 10,
separation_axis: str = "y",
z_position: Iterable[float] | float = None,
thickness: float | Iterable[float] = 2.0,
colors: str | Iterable[str] | np.ndarray | Iterable[np.ndarray] = "w",
alpha: float = 1.0,
cmap: Iterable[str] | str = None,
cmap_values: np.ndarray | List = None,
name: str = None,
metadata: Iterable[Any] | np.ndarray = None,
separation: float = 10.0,
separation_axis: str = "y",
*args,
**kwargs,
):
Expand All @@ -492,33 +497,37 @@ def __init__(

Parameters
----------
data: list of array-like
data: list of array-like or array
List of line data to plot, each element must be a 1D, 2D, or 3D numpy array
if elements are 2D, interpreted as [y_vals, n_lines]

z_position: list of float or float, optional
z_position: Iterable of float or float, optional
| if ``float``, single position will be used for all lines
| if ``list`` of ``float``, each value will apply to individual lines
| if ``list`` of ``float``, each value will apply to the individual lines

thickness: float or list of float, default 2.0
thickness: float or Iterable of float, default 2.0
| if ``float``, single thickness will be used for all lines
| if ``list`` of ``float``, each value will apply to the individual lines

colors: str, RGBA array, list of RGBA array, or list of str, default "w"
colors: str, RGBA array, Iterable of RGBA array, or Iterable of str, default "w"
| if single ``str`` such as "w", "r", "b", etc, represents a single color for all lines
| if single ``RGBA array`` (tuple or list of size 4), represents a single color for all lines
| is ``list`` of ``str``, represents color for each individual line, example ["w", "b", "r",...]
| if ``list`` of ``RGBA array`` of shape [data_size, 4], represents a single RGBA array for each line
| if ``list`` of ``str``, represents color for each individual line, example ["w", "b", "r",...]
| if ``RGBA array`` of shape [data_size, 4], represents a single RGBA array for each line

cmap: list of str or str, optional
cmap: Iterable of str or str, optional
| if ``str``, single cmap will be used for all lines
| if ``list`` of ``str``, each cmap will apply to the individual lines

.. note::
``cmap`` overrides any arguments passed to ``colors``

name: str, optional
name of the line stack
cmap_values: 1D array-like or Iterable of numerical values, optional
if provided, these values are used to map the colors from the cmap

metadata: Iterable or array
metadata associated with this collection, this is for the user to manage.
``len(metadata)`` must be same as ``len(data)``

separation: float, default 10
space in between each line graphic in the stack
Expand All @@ -529,13 +538,9 @@ def __init__(
name: str, optional
name of the line stack

args
passed to LineCollection

kwargs
passed to LineCollection


Features
--------

Expand All @@ -549,8 +554,12 @@ def __init__(
z_position=z_position,
thickness=thickness,
colors=colors,
alpha=alpha,
cmap=cmap,
cmap_values=cmap_values,
metadata=metadata,
name=name,
*args,
**kwargs,
)

Expand Down
6 changes: 3 additions & 3 deletions fastplotlib/graphics/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ScatterGraphic(Graphic):
def __init__(
self,
data: np.ndarray,
sizes: Union[int, float, np.ndarray, list] = 1,
colors: np.ndarray = "w",
sizes: float | np.ndarray | Iterable[float] = 1,
colors: str | np.ndarray | Iterable[str] = "w",
alpha: float = 1.0,
cmap: str = None,
cmap_values: Union[np.ndarray, List] = None,
cmap_values: np.ndarray | List = None,
z_position: float = 0.0,
*args,
**kwargs,
Expand Down
1 change: 0 additions & 1 deletion fastplotlib/layouts/_defaults.py

This file was deleted.

4 changes: 1 addition & 3 deletions fastplotlib/layouts/_frame/_ipywidget_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from math import copysign
from functools import partial
from pathlib import Path
from typing import *


from ipywidgets.widgets import (
IntSlider,
Expand Down Expand Up @@ -238,7 +236,7 @@ def __init__(self, iw):
tooltip="reset vmin/vmax and reset histogram using current frame",
)

self.sliders: Dict[str, IntSlider] = dict()
self.sliders: dict[str, IntSlider] = dict()

# only for xy data, no time point slider needed
if self.iw.ndim == 2:
Expand Down
4 changes: 1 addition & 3 deletions fastplotlib/layouts/_frame/_jupyter_output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import *

from ipywidgets import VBox, Widget
from sidecar import Sidecar
from IPython.display import display
Expand All @@ -20,7 +18,7 @@ def __init__(
make_toolbar: bool,
use_sidecar: bool,
sidecar_kwargs: dict,
add_widgets: List[Widget],
add_widgets: list[Widget],
):
"""

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy