Skip to content

Commit

Permalink
modified test setup code to work for opensearch
Browse files Browse the repository at this point in the history
  • Loading branch information
LEFTA98 committed Jul 8, 2022
1 parent 4737995 commit 983b43d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
2 changes: 2 additions & 0 deletions tests/dataframe/test_count_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class TestDataFrameCount(TestData):
]

def test_count(self, df):


df.load_dataset("ecommerce")
df.count()

Expand Down
2 changes: 1 addition & 1 deletion tests/dataframe/test_filter_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_filter_index_order(self):
# Filtering dataframe should retain order of items
ed_flights = self.ed_flights()

ed_index = ed_flights().to_pandas().index
ed_index = ed_flights.to_pandas().index
items = list(ed_index[:5])
items.reverse()

Expand Down
6 changes: 3 additions & 3 deletions tests/dataframe/test_init_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def test_init(self):

# Construct invalid DataFrame (throws)
with pytest.raises(ValueError):
ed.DataFrame(es_client=ES_TEST_CLIENT)
ed.DataFrame(os_client=ES_TEST_CLIENT)

# Construct invalid DataFrame (throws)
with pytest.raises(ValueError):
ed.DataFrame(es_index_pattern=FLIGHTS_INDEX_NAME)
ed.DataFrame(os_index_pattern=FLIGHTS_INDEX_NAME)

# Good constructors
ed.DataFrame(ES_TEST_CLIENT, FLIGHTS_INDEX_NAME)
ed.DataFrame(es_client=ES_TEST_CLIENT, es_index_pattern=FLIGHTS_INDEX_NAME)
ed.DataFrame(os_client=ES_TEST_CLIENT, os_index_pattern=FLIGHTS_INDEX_NAME)

qc = QueryCompiler(client=ES_TEST_CLIENT, index_pattern=FLIGHTS_INDEX_NAME)
ed.DataFrame(_query_compiler=qc)
16 changes: 8 additions & 8 deletions tests/dataframe/test_metrics_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_ecommerce_selected_non_numeric_source_fields(self):
columns = [
"category",
"currency",
"customer_birth_date",
"customer_first_name",
"user",
]
Expand All @@ -133,7 +132,6 @@ def test_ecommerce_selected_mixed_numeric_source_fields(self):
"category",
"currency",
"taxless_total_price",
"customer_birth_date",
"total_quantity",
"customer_first_name",
"user",
Expand Down Expand Up @@ -507,13 +505,15 @@ def test_flights_idx_on_index(self):
["AvgTicketPrice", "FlightDelayMin", "dayOfWeek"]
)

pd_idxmax = pd_flights.idxmax()
ed_idxmax = ed_flights.idxmax()
assert_series_equal(pd_idxmax, ed_idxmax)
pd_idxmax = list(pd_flights.idxmax())
ed_idxmax = list(ed_flights.idxmax())
assert_frame_equal(pd_flights.filter(items=pd_idxmax, axis=0).reset_index(),
ed_flights.filter(items=ed_idxmax, axis=0).to_pandas().reset_index())

pd_idxmin = pd_flights.idxmin()
ed_idxmin = ed_flights.idxmin()
assert_series_equal(pd_idxmin, ed_idxmin)
pd_idxmin = list(pd_flights.idxmin())
ed_idxmin = list(ed_flights.idxmin())
assert_frame_equal(pd_flights.filter(items=pd_idxmin, axis=0).reset_index(),
ed_flights.filter(items=ed_idxmin, axis=0).to_pandas().reset_index())

def test_flights_idx_on_columns(self):
match = "This feature is not implemented yet for 'axis = 1'"
Expand Down
31 changes: 17 additions & 14 deletions tests/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.

import pandas as pd
from elasticsearch import helpers
from elasticsearch._sync.client import Elasticsearch
from opensearchpy.client import OpenSearch
from opensearchpy import helpers

from tests import (
ECOMMERCE_FILE_NAME,
Expand Down Expand Up @@ -53,9 +53,9 @@ def _setup_data(es):

# Delete index
print("Deleting index:", index_name)
es.options(ignore_status=[400, 404]).indices.delete(index=index_name)
es.indices.delete(index=index_name, ignore_unavailable=True)
print("Creating index:", index_name)
es.indices.create(index=index_name, **mapping)
es.indices.create(index=index_name, body=mapping)

df = pd.read_json(json_file_name, lines=True)

Expand Down Expand Up @@ -85,28 +85,31 @@ def _setup_data(es):
print("Done", index_name)


def _update_max_compilations_limit(es: Elasticsearch, limit="10000/1m"):
def _update_max_compilations_limit(es: OpenSearch, limit="10000/1m"):
print("Updating script.max_compilations_rate to ", limit)
es.cluster.put_settings(
transient={
"script.max_compilations_rate": "use-context",
"script.context.field.max_compilations_rate": limit,
body={
"transient": {
"script.max_compilations_rate": "use-context",
"senecccbnijrkjjerviltfgjlibhffleggivlgcrhgthi"
"cript.context.field.max_compilations_rate": limit,
}
}
)


def _setup_test_mappings(es: Elasticsearch):
def _setup_test_mappings(es: OpenSearch):
# Create a complex mapping containing many Elasticsearch features
es.options(ignore_status=[400, 404]).indices.delete(index=TEST_MAPPING1_INDEX_NAME)
es.indices.create(index=TEST_MAPPING1_INDEX_NAME, **TEST_MAPPING1)
es.indices.delete(index=TEST_MAPPING1_INDEX_NAME, ignore_unavailable=True)
es.indices.create(index=TEST_MAPPING1_INDEX_NAME, body=TEST_MAPPING1)


def _setup_test_nested(es):
es.options(ignore_status=[400, 404]).indices.delete(
index=TEST_NESTED_USER_GROUP_INDEX_NAME
es.indices.delete(
index=TEST_NESTED_USER_GROUP_INDEX_NAME, ignore_unavailable=True
)
es.indices.create(
index=TEST_NESTED_USER_GROUP_INDEX_NAME, **TEST_NESTED_USER_GROUP_MAPPING
index=TEST_NESTED_USER_GROUP_INDEX_NAME, body=TEST_NESTED_USER_GROUP_MAPPING
)

helpers.bulk(es, TEST_NESTED_USER_GROUP_DOCS)
Expand Down

0 comments on commit 983b43d

Please sign in to comment.