Skip to content

Commit

Permalink
Renamed from_indexed_dicts to from_struct
Browse files Browse the repository at this point in the history
  • Loading branch information
javiber committed Apr 9, 2024
1 parent ce03dca commit bf3638d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 81 deletions.
2 changes: 1 addition & 1 deletion docs/public_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"to_tensorflow_dataset",
"from_tensorflow_record",
"to_tensorflow_record",
"from_indexed_dicts",
"from_struct",
# DTYPES
"float64",
"float32",
Expand Down
85 changes: 30 additions & 55 deletions temporian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,47 @@
# PUBLIC API SYMBOLS #
# ================== #

# EventSetNodes
from temporian.core.data.node import EventSetNode
from temporian.core.data.node import input_node, input_node_from_schema

# Dtypes
from temporian.core.data.dtype import float64
from temporian.core.data.dtype import float32
from temporian.core.data.dtype import int32
from temporian.core.data.dtype import int64
from temporian.core.data.dtype import bool_
from temporian.core.data.dtype import str_
from temporian.core.data.dtype import bytes_

# Schema
from temporian.core.data.schema import Schema, FeatureSchema, IndexSchema

# Durations
from temporian.api import duration

# Types
from temporian.core import types
# Compilation
from temporian.core.compilation import compile
# Dtypes
from temporian.core.data.dtype import (bool_, bytes_, float32, float64, int32,
int64, str_)
# EventSetNodes
from temporian.core.data.node import (EventSetNode, input_node,
input_node_from_schema)
# Schema
from temporian.core.data.schema import FeatureSchema, IndexSchema, Schema
# Graph execution
from temporian.core.evaluation import has_leak, run
from temporian.core.operators.combine import combine
from temporian.core.operators.glue import glue
# Serialization
from temporian.core.serialization import load, load_graph, save, save_graph
# EventSets
from temporian.implementation.numpy.data.event_set import EventSet, IndexData
from temporian.implementation.numpy.data.io import event_set, from_indexed_dicts

# Serialization
from temporian.core.serialization import save
from temporian.core.serialization import load
from temporian.core.serialization import save_graph
from temporian.core.serialization import load_graph

# Graph execution
from temporian.core.evaluation import run
from temporian.core.evaluation import has_leak

# IO
from temporian.io.csv import to_csv
from temporian.io.csv import from_csv
from temporian.io.pandas import to_pandas
from temporian.io.numpy import to_numpy
from temporian.io.pandas import from_pandas
from temporian.io.parquet import from_parquet
from temporian.io.parquet import to_parquet
from temporian.io.polars import to_polars
from temporian.io.polars import from_polars
from temporian.io.tensorflow import to_tensorflow_dataset
from temporian.io.tensorflow import from_tensorflow_record
from temporian.io.tensorflow import to_tensorflow_record

from temporian.implementation.numpy.data.io import event_set, from_struct
# Plotting
from temporian.implementation.numpy.data.plotter import plot

# Compilation
from temporian.core.compilation import compile

# Types
from temporian.core import types

# Runtime check
from temporian.utils.typecheck import runtime_check_raise_exception

# IO
from temporian.io.csv import from_csv, to_csv
from temporian.io.numpy import to_numpy
from temporian.io.pandas import from_pandas, to_pandas
from temporian.io.parquet import from_parquet, to_parquet
from temporian.io.polars import from_polars, to_polars
from temporian.io.tensorflow import (from_tensorflow_record,
to_tensorflow_dataset,
to_tensorflow_record)
# Config
from temporian.utils import config
# Runtime check
from temporian.utils.typecheck import runtime_check_raise_exception

# --- OPERATORS ---

from temporian.core.operators.glue import glue
from temporian.core.operators.combine import combine

# Remove automatic file tree symbols from public API
# pylint: disable=undefined-variable
Expand Down
29 changes: 13 additions & 16 deletions temporian/implementation/numpy/data/io.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
from typing import Any, List, Optional, Union, Dict, Tuple

import logging
from typing import Any, Dict, List, Optional, Tuple, Union

import numpy as np
from temporian.implementation.numpy.data.dtype_normalization import (
normalize_features,
normalize_timestamps,
numpy_array_to_tp_dtype,
)

from temporian.utils.typecheck import typecheck
from temporian.implementation.numpy.data.event_set import EventSet, IndexData
from temporian.core.data.dtype import DType
from temporian.core.data.schema import FeatureSchema, IndexSchema, Schema
from temporian.core.evaluation import run
from temporian.core.operators.add_index import add_index
from temporian.core.data.schema import Schema, IndexSchema, FeatureSchema
from temporian.core.data.dtype import DType
from temporian.implementation.numpy.data.dtype_normalization import (
numpy_dtype_to_tp_dtype,
normalize_index_item,
normalize_features,
normalize_index_item,
normalize_timestamps,
numpy_array_to_tp_dtype,
numpy_dtype_to_tp_dtype,
)
from temporian.implementation.numpy.data.event_set import EventSet, IndexData
from temporian.utils.typecheck import typecheck

# Array of values as feed by the user.
DataArray = Union[List[Any], np.ndarray, "pandas.Series"]
Expand Down Expand Up @@ -208,21 +205,21 @@ def event_set(


@typecheck
def from_indexed_dicts(
def from_struct(
data: List[Tuple[Dict[str, Any], Dict[str, DataArray]]],
timestamps: str = "timestamp",
is_unix_timestamp: bool = False,
) -> EventSet:
"""Creates an [`EventSet`][temporian.EventSet] from indexed data.
Unlike `event_set`, `from_indexed_dicts` expects for the data to be already
Unlike `event_set`, `from_struct` expects for the data to be already
split by index value. Supported values for timestamps, indexes, and
features as similar to `event_set`.
Usage examples:
```python
>>> evset = tp.from_indexed_dicts(
>>> evset = tp.from_struct(
... [
... (
... {"i1": 1, "i2": "A"},
Expand Down
18 changes: 9 additions & 9 deletions temporian/implementation/numpy/data/test/io_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from absl.testing import absltest
import math
from datetime import datetime

from absl import logging
import numpy as np
import math
import pandas as pd
from absl import logging
from absl.testing import absltest
from numpy.testing import assert_array_equal
from datetime import datetime

from temporian.implementation.numpy.data.io import event_set, from_indexed_dicts
from temporian.implementation.numpy.data.event_set import IndexData, EventSet
from temporian.core.data.schema import Schema
from temporian.core.data.dtype import DType
from temporian.core.data.schema import Schema
from temporian.implementation.numpy.data.event_set import EventSet, IndexData
from temporian.implementation.numpy.data.io import event_set, from_struct


class IOTest(absltest.TestCase):
Expand Down Expand Up @@ -199,8 +199,8 @@ def test_feature_wrong_type(self):
},
)

def test_from_indexed_dicts(self):
evset = from_indexed_dicts(
def test_from_struct(self):
evset = from_struct(
[
(
{"i1": 1, "i2": "A"},
Expand Down

0 comments on commit bf3638d

Please sign in to comment.