-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bd63b1
commit 87bce7e
Showing
10 changed files
with
666 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import airtrafficsim.units as u | ||
|
||
print((u.KILOGRAM * u.METER * u.SECOND**-2).to_siunitx()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Generic, overload | ||
|
||
from .annotations import Quantity, Units | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
import polars as pl | ||
from typing_extensions import Self | ||
|
||
|
||
def into_latex(unit: Units) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
@dataclass | ||
class Column(Generic[Units]): | ||
quantity: Quantity[Units] | ||
display_name: str | None = None | ||
symbol: str | None = None | ||
identifier: str | None = None | ||
""" | ||
A unique identifier for retrieving the series in a dataframe (optional) | ||
""" | ||
|
||
@classmethod | ||
def from_quantity(cls, quantity: Quantity[Units]) -> Self: | ||
if (doc := quantity.__doc__) is not None: | ||
display_name = doc.split("\n")[0].split(",")[0] | ||
print(display_name) | ||
return cls(quantity) | ||
|
||
@property | ||
def label(self) -> str: | ||
if self.display_name and self.symbol: | ||
label = f"{self.display_name}, {self.symbol}" | ||
elif self.display_name: | ||
label = self.display_name | ||
elif self.symbol: | ||
label = f"{self.symbol}" | ||
else: | ||
raise ValueError("Either display_name or symbol must be provided.") | ||
if self.quantity.unit is not None: # hide for dimensionless | ||
label += f" (${self.quantity.unit}$)" | ||
return label | ||
|
||
@overload | ||
def __call__(self, df: pl.DataFrame) -> pl.Series: ... | ||
|
||
@overload | ||
def __call__(self, df: Any) -> Any: ... | ||
|
||
def __call__(self, df: Any) -> Any: | ||
"""Returns series in the dataframe.""" | ||
return df[self.identifier] |
Oops, something went wrong.