Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,27 @@ def test_get(self):
columns=pd.Index([0, 1], dtype="int64", name="symbol"),
),
)

class UnnamedSeriesData(vbt.Data):
@classmethod
def download_symbol(cls, symbol):
return pd.Series(
[1.0, 2.0, 3.0],
index=pd.date_range("2021-01-01", "2021-01-03"),
)

pd.testing.assert_series_equal(
UnnamedSeriesData.download(["RANDNX1", "RANDNX2"]).get(column="RANDNX1"),
pd.Series(
[1.0, 2.0, 3.0],
index=pd.DatetimeIndex(
["2021-01-01 00:00:00", "2021-01-02 00:00:00", "2021-01-03 00:00:00"],
freq="D",
tz=timezone.utc,
),
name="RANDNX1",
),
)
pd.testing.assert_frame_equal(
MyData.download([0, 1], shape=(5, 3), columns=["feat0", "feat1", "feat2"]).get("feat0"),
pd.DataFrame(
Expand Down
9 changes: 8 additions & 1 deletion vectorbt/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,14 @@ def get(self, column: tp.Optional[tp.Label] = None, **kwargs) -> tp.MaybeTuple[t

concat_data = self.concat(**kwargs)
if len(concat_data) == 1:
return tuple(concat_data.values())[0]
single_data = tuple(concat_data.values())[0]
if column is not None:
if isinstance(column, list):
if isinstance(single_data, pd.DataFrame) and all(c in single_data.columns for c in column):
return single_data[column]
elif isinstance(single_data, pd.DataFrame) and column in single_data.columns:
return single_data[column]
return single_data
if column is not None:
if isinstance(column, list):
return tuple([concat_data[c] for c in column])
Expand Down
Loading