Skip to content

Commit 7bb9bae

Browse files
authored
rename DataChain's create_empty to from_records (#215)
1 parent a8bc786 commit 7bb9bae

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/datachain/lib/dc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ def from_values(
11241124
def _func_fr() -> Iterator[tuple_type]: # type: ignore[valid-type]
11251125
yield from tuples
11261126

1127-
chain = DataChain.create_empty(DataChain.DEFAULT_FILE_RECORD, session=session)
1127+
chain = DataChain.from_records(DataChain.DEFAULT_FILE_RECORD, session=session)
11281128
if object_name:
11291129
output = {object_name: DataChain._dict_to_data_model(object_name, output)} # type: ignore[arg-type]
11301130
return chain.gen(_func_fr, output=output)
@@ -1441,22 +1441,23 @@ def to_parquet(
14411441
)
14421442

14431443
@classmethod
1444-
def create_empty(
1444+
def from_records(
14451445
cls,
14461446
to_insert: Optional[Union[dict, list[dict]]],
14471447
session: Optional[Session] = None,
14481448
) -> "DataChain":
1449-
"""Create empty chain. Returns a chain. This method is used for programmatically
1450-
generating a chains in contrast of reading data from storages or other sources.
1449+
"""Create a DataChain from the provided records. This method can be used for
1450+
programmatically generating a chain in contrast of reading data from storages
1451+
or other sources.
14511452
14521453
Parameters:
14531454
to_insert : records (or a single record) to insert. Each record is
14541455
a dictionary of signals and theirs values.
14551456
14561457
Example:
14571458
```py
1458-
empty = DataChain.create_empty()
1459-
single_record = DataChain.create_empty(DataChain.DEFAULT_FILE_RECORD)
1459+
empty = DataChain.from_records()
1460+
single_record = DataChain.from_records(DataChain.DEFAULT_FILE_RECORD)
14601461
```
14611462
"""
14621463
session = Session.get(session)

tests/unit/lib/test_datachain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_pandas_incorrect_column_names(catalog):
9595

9696

9797
def test_from_features_basic(catalog):
98-
ds = DataChain.create_empty(DataChain.DEFAULT_FILE_RECORD)
98+
ds = DataChain.from_records(DataChain.DEFAULT_FILE_RECORD)
9999
ds = ds.gen(lambda prm: [File(name="")] * 5, params="parent", output={"file": File})
100100

101101
ds_name = "my_ds"
@@ -109,7 +109,7 @@ def test_from_features_basic(catalog):
109109

110110

111111
def test_from_features(catalog):
112-
ds = DataChain.create_empty(DataChain.DEFAULT_FILE_RECORD)
112+
ds = DataChain.from_records(DataChain.DEFAULT_FILE_RECORD)
113113
ds = ds.gen(
114114
lambda prm: list(zip([File(name="")] * len(features), features)),
115115
params="parent",
@@ -138,7 +138,7 @@ def test_datasets(catalog):
138138

139139

140140
def test_preserve_feature_schema(catalog):
141-
ds = DataChain.create_empty(DataChain.DEFAULT_FILE_RECORD)
141+
ds = DataChain.from_records(DataChain.DEFAULT_FILE_RECORD)
142142
ds = ds.gen(
143143
lambda prm: list(zip([File(name="")] * len(features), features, features)),
144144
params="parent",

0 commit comments

Comments
 (0)