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
29 changes: 3 additions & 26 deletions btrdb/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,13 @@ def arrow_to_series(streamset, agg="mean", name_callable=None):
return [arrow_df[col] for col in arrow_df]


def arrow_to_dataframe(
streamset, columns=None, agg=None, name_callable=None
) -> pd.DataFrame:
def arrow_to_dataframe(streamset, agg=None, name_callable=None) -> pd.DataFrame:
"""
Returns a Pandas DataFrame object indexed by time and using the values of a
stream for each column.

Parameters
----------
columns: sequence
column names to use for DataFrame. Deprecated and not compatible with name_callable.

agg : List[str], default: ["mean"]
Specify the StatPoint fields (e.g. aggregating function) to create the dataframe
from. Must be one or more of "min", "mean", "max", "count", "stddev", or "all". This
Expand All @@ -175,13 +170,6 @@ def arrow_to_dataframe(
raise ImportError(
f"Please install Pandas and pyarrow to use this transformation function. ErrorMessage: {err}"
)
# deprecation warning added in v5.8
if columns:
warn(
"the columns argument is deprecated and will be removed in a future release",
DeprecationWarning,
stacklevel=2,
)

if agg is None:
agg = ["mean"]
Expand Down Expand Up @@ -227,16 +215,13 @@ def arrow_to_dataframe(
return tmp.to_pandas(date_as_object=False, types_mapper=pd.ArrowDtype)


def to_dataframe(streamset, columns=None, agg="mean", name_callable=None):
def to_dataframe(streamset, agg="mean", name_callable=None):
"""
Returns a Pandas DataFrame object indexed by time and using the values of a
stream for each column.

Parameters
----------
columns: sequence
column names to use for DataFrame. Deprecated and not compatible with name_callable.

agg : str, default: "mean"
Specify the StatPoint field (e.g. aggregating function) to create the Series
from. Must be one of "min", "mean", "max", "count", "stddev", or "all". This
Expand All @@ -253,14 +238,6 @@ def to_dataframe(streamset, columns=None, agg="mean", name_callable=None):
except ImportError:
raise ImportError("Please install Pandas to use this transformation function.")

# deprecation warning added in v5.8
if columns:
warn(
"the columns argument is deprecated and will be removed in a future release",
DeprecationWarning,
stacklevel=2,
)

# TODO: allow this at some future point
if agg == "all" and name_callable is not None:
raise AttributeError(
Expand Down Expand Up @@ -288,7 +265,7 @@ def to_dataframe(streamset, columns=None, agg="mean", name_callable=None):
]
df.columns = pd.MultiIndex.from_tuples(stream_names)
else:
df.columns = columns if columns else _stream_names(streamset, name_callable)
df.columns = _stream_names(streamset, name_callable)

return df

Expand Down
21 changes: 7 additions & 14 deletions tests/btrdb/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def test_to_series(self, streamset):

def test_to_series_name_lambda(self, streamset):
"""
assert to_dateframe uses name lambda
assert to_series uses name lambda
"""
result = streamset.to_series(name_callable=lambda s: s.name)
assert [s.name for s in result] == ["stream0", "stream1", "stream2", "stream3"]
Expand Down Expand Up @@ -691,23 +691,16 @@ def test_to_dataframe(self, streamset):
df.set_index("time", inplace=True)
assert to_dataframe(streamset).equals(df)

def test_to_dataframe_column_issues_warning(self, statpoint_streamset):
def test_to_dataframe_column_issues_error(self, statpoint_streamset):
"""
assert to_dateframe with column argument issues warning
assert to_dateframe with column argument issues error
"""
columns = ["test/cats", "test/dogs", "test/horses", "test/fishes"]
with pytest.deprecated_call():
with pytest.raises(TypeError) as unexpected_key_err:
statpoint_streamset.to_dataframe(columns=columns)

def test_to_dataframe_column(self, statpoint_streamset):
"""
assert to_dateframe with column argument actually renames columns
"""
columns = ["test/cats", "test/dogs", "test/horses", "test/fishes"]
with pytest.deprecated_call():
df = statpoint_streamset.to_dataframe(columns=columns)

assert df.columns.tolist() == columns
assert "got an unexpected keyword argument 'columns'" in str(
unexpected_key_err.value
)

def test_to_dataframe_multindex(self, statpoint_streamset):
"""
Expand Down