| 586 | """ |
| 587 | |
| 588 | def __init__(self, data=None, num_rows=None): |
| 589 | if data is None: |
| 590 | self._columns = dict() |
| 591 | self._num_rows = 0 if num_rows is None else num_rows |
| 592 | else: |
| 593 | assert not isinstance(data, Frame) # sanity check for code refactor |
| 594 | # Note that we always create a new column for the given data. |
| 595 | # This avoids two frames accidentally sharing the same column. |
| 596 | self._columns = { |
| 597 | k: v if isinstance(v, LazyFeature) else Column.create(v) |
| 598 | for k, v in data.items() |
| 599 | } |
| 600 | self._num_rows = num_rows |
| 601 | # infer num_rows & sanity check |
| 602 | for name, col in self._columns.items(): |
| 603 | if isinstance(col, LazyFeature): |
| 604 | continue |
| 605 | if self._num_rows is None: |
| 606 | self._num_rows = len(col) |
| 607 | elif len(col) != self._num_rows: |
| 608 | raise DGLError( |
| 609 | "Expected all columns to have same # rows (%d), " |
| 610 | "got %d on %r." % (self._num_rows, len(col), name) |
| 611 | ) |
| 612 | |
| 613 | # Initializer for empty values. Initializer is a callable. |
| 614 | # If is none, then a warning will be raised |
| 615 | # in the first call and zero initializer will be used later. |
| 616 | self._initializers = {} # per-column initializers |
| 617 | self._default_initializer = None |
| 618 | |
| 619 | def _set_zero_default_initializer(self): |
| 620 | """Set the default initializer to be zero initializer.""" |