Coverage for src/dummypy/things.py: 100%
16 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-09-28 16:04 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-09-28 16:04 +0000
1"""Core data structures for the dummypy analytics library."""
3import attrs
4import numpy as np
5import pandas as pd
8@attrs.define
9class Grid:
10 """A grid representing data points for analytics calculations.
12 Creates two DataFrames (x and y) with goal-like structure for data analysis.
14 Args:
15 n: Maximum size for the grid (default: 10)
16 """
18 n: int = attrs.field(init=True, repr=True, default=10)
19 x: pd.DataFrame = attrs.field(repr=False, init=False)
20 y: pd.DataFrame = attrs.field(repr=False, init=False)
22 def __attrs_post_init__(self):
23 """Initialize the x and y data matrices after object creation."""
24 nn = np.arange(self.n + 1)
25 cols = [str(n) for n in nn]
26 data = np.tile(nn, (self.n + 1, 1))
27 self.y = pd.DataFrame(data, index=cols, columns=cols)
28 self.x = self.y.T
30 def diff(self) -> pd.DataFrame:
31 """Returns a grid of differences."""
32 return self.x - self.y