A grid representing data points for analytics calculations.
Creates two DataFrames (x and y) with goal-like structure for data analysis.
Parameters:
| Name |
Type |
Description |
Default |
n
|
|
Maximum size for the grid (default: 10). Must be a non-negative
integer.
|
required
|
Raises:
| Type |
Description |
TypeError
|
If n is not an integer (e.g. a float or a bool).
|
ValueError
|
|
Source code in src/dummypy/things.py
| @attrs.define
class Grid:
"""A grid representing data points for analytics calculations.
Creates two DataFrames (x and y) with goal-like structure for data analysis.
Args:
n: Maximum size for the grid (default: 10). Must be a non-negative
integer.
Raises:
TypeError: If ``n`` is not an integer (e.g. a float or a bool).
ValueError: If ``n`` is negative.
"""
n: int = attrs.field(init=True, repr=True, default=10, validator=_check_n)
x: pd.DataFrame = attrs.field(repr=False, init=False)
y: pd.DataFrame = attrs.field(repr=False, init=False)
def __attrs_post_init__(self) -> None:
"""Initialize the x and y data matrices after object creation."""
nn = np.arange(self.n + 1)
cols = [str(n) for n in nn]
data = np.tile(nn, (self.n + 1, 1))
self.y = pd.DataFrame(data, index=pd.Index(cols), columns=pd.Index(cols))
self.x = self.y.T
def diff(self) -> pd.DataFrame:
"""Returns a grid of differences.
Returns:
DataFrame of element-wise differences (x - y).
"""
return self.x - self.y
|
__attrs_post_init__()
Initialize the x and y data matrices after object creation.
Source code in src/dummypy/things.py
| def __attrs_post_init__(self) -> None:
"""Initialize the x and y data matrices after object creation."""
nn = np.arange(self.n + 1)
cols = [str(n) for n in nn]
data = np.tile(nn, (self.n + 1, 1))
self.y = pd.DataFrame(data, index=pd.Index(cols), columns=pd.Index(cols))
self.x = self.y.T
|
diff()
Returns a grid of differences.
Returns:
| Type |
Description |
DataFrame
|
DataFrame of element-wise differences (x - y).
|
Source code in src/dummypy/things.py
| def diff(self) -> pd.DataFrame:
"""Returns a grid of differences.
Returns:
DataFrame of element-wise differences (x - y).
"""
return self.x - self.y
|