Skip to content

Commit

Permalink
Replaced deprecated _construct_axes_from_arguments method in pandas 2…
Browse files Browse the repository at this point in the history
….x.x and fixed quantile keyword argument

Signed-off-by: Yerzhaisang <tasqali1697@gmail.com>
  • Loading branch information
Yerzhaisang committed Feb 13, 2024
1 parent 24163a0 commit 4067fcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 1 addition & 3 deletions opensearch_py_ml/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,7 @@ def drop(
axis = pd.DataFrame._get_axis_name(axis)
axes = {axis: labels}
elif index is not None or columns is not None:
axes, _ = pd.DataFrame()._construct_axes_from_arguments(
(index, columns), {}
)
axes = {'index': index, 'columns': columns}
else:
raise ValueError(
"Need to specify at least one of 'labels', 'index' or 'columns'"
Expand Down
3 changes: 3 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ def mad(x):
numeric_columns = x.select_dtypes(include=["number", "bool"]).columns
x = x[numeric_columns]
return np.fabs(x - x.mean()).mean()

def quantile(x, numeric_only=None):
return x.quantile()
21 changes: 14 additions & 7 deletions tests/dataframe/test_metrics_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import pytest
from pandas.testing import assert_frame_equal, assert_series_equal

from tests.common import TestData, assert_almost_equal
from tests.common import TestData, assert_almost_equal, quantile, mad


class TestDataFrameMetrics(TestData):
Expand Down Expand Up @@ -81,9 +81,10 @@ def test_flights_extended_metrics(self):
logger.setLevel(logging.DEBUG)

for func in self.extended_funcs:
pd_metric = getattr(pd_flights, func)(
**({"numeric_only": True} if func != "mad" else {})
)
if func == "mad":
pd_metric = mad(pd_flights)
else:
pd_metric = getattr(pd_flights, func)(numeric_only=True)
oml_metric = getattr(oml_flights, func)(numeric_only=True)

pd_value = pd_metric["AvgTicketPrice"]
Expand All @@ -101,7 +102,10 @@ def test_flights_extended_metrics_nan(self):
]

for func in self.extended_funcs:
pd_metric = getattr(pd_flights_1, func)()
if func == "mad":
pd_metric = mad(pd_flights_1)
else:
pd_metric = getattr(pd_flights_1, func)()
oml_metric = getattr(oml_flights_1, func)(numeric_only=False)

assert_series_equal(pd_metric, oml_metric, check_exact=False)
Expand All @@ -111,7 +115,10 @@ def test_flights_extended_metrics_nan(self):
oml_flights_0 = oml_flights[oml_flights.FlightNum == "XXX"][["AvgTicketPrice"]]

for func in self.extended_funcs:
pd_metric = getattr(pd_flights_0, func)()
if func == "mad":
pd_metric = mad(pd_flights_0)
else:
pd_metric = getattr(pd_flights_0, func)()
oml_metric = getattr(oml_flights_0, func)(numeric_only=False)

assert_series_equal(pd_metric, oml_metric, check_exact=False)
Expand Down Expand Up @@ -498,7 +505,7 @@ def test_flights_agg_quantile(self, numeric_only):
["AvgTicketPrice", "FlightDelayMin", "dayOfWeek"]
)

pd_quantile = pd_flights.agg(["quantile", "min"], numeric_only=numeric_only)
pd_quantile = pd_flights.agg([quantile, "min"], numeric_only=numeric_only)
oml_quantile = oml_flights.agg(["quantile", "min"], numeric_only=numeric_only)

assert_frame_equal(
Expand Down

0 comments on commit 4067fcf

Please sign in to comment.