# SPDX-License-Identifier: Apache-2.0 # The OpenSearch Contributors require contributions made to # this file be licensed under the Apache-2.0 license or a # compatible open source license. # Any modifications Copyright OpenSearch Contributors. See # GitHub history for details. # Licensed to Elasticsearch B.V. under one or more contributor # license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright # ownership. Elasticsearch B.V. licenses this file to you under # the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # File called _pytest for PyCharm compatability from tests.common import TestData, assert_pandas_opensearch_py_ml_frame_equal class TestDataFrameHeadTail(TestData): def test_head(self): oml_flights = self.oml_flights() pd_flights = self.pd_flights() oml_head_10 = oml_flights.head(10) pd_head_10 = pd_flights.head(10) assert_pandas_opensearch_py_ml_frame_equal(pd_head_10, oml_head_10) oml_head_8 = oml_head_10.head(8) pd_head_8 = pd_head_10.head(8) assert_pandas_opensearch_py_ml_frame_equal(pd_head_8, oml_head_8) oml_head_20 = oml_head_10.head(20) pd_head_20 = pd_head_10.head(20) assert_pandas_opensearch_py_ml_frame_equal(pd_head_20, oml_head_20) def test_tail(self): oml_flights = self.oml_flights() pd_flights = self.pd_flights() oml_tail_10 = oml_flights.tail(10) pd_tail_10 = pd_flights.tail(10) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_10, oml_tail_10) oml_tail_8 = oml_tail_10.tail(8) pd_tail_8 = pd_tail_10.tail(8) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_8, oml_tail_8) oml_tail_20 = oml_tail_10.tail(20) pd_tail_20 = pd_tail_10.tail(20) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_20, oml_tail_20) def test_head_tail(self): oml_flights = self.oml_flights() pd_flights = self.pd_flights() oml_head_10 = oml_flights.head(10) pd_head_10 = pd_flights.head(10) assert_pandas_opensearch_py_ml_frame_equal(pd_head_10, oml_head_10) oml_tail_8 = oml_head_10.tail(8) pd_tail_8 = pd_head_10.tail(8) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_8, oml_tail_8) oml_tail_5 = oml_tail_8.tail(5) pd_tail_5 = pd_tail_8.tail(5) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_5, oml_tail_5) oml_tail_4 = oml_tail_5.tail(4) pd_tail_4 = pd_tail_5.tail(4) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_4, oml_tail_4) def test_tail_head(self): oml_flights = self.oml_flights() pd_flights = self.pd_flights() oml_tail_10 = oml_flights.tail(10) pd_tail_10 = pd_flights.tail(10) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_10, oml_tail_10) oml_head_8 = oml_tail_10.head(8) pd_head_8 = pd_tail_10.head(8) assert_pandas_opensearch_py_ml_frame_equal(pd_head_8, oml_head_8) oml_tail_5 = oml_head_8.tail(5) pd_tail_5 = pd_head_8.tail(5) assert_pandas_opensearch_py_ml_frame_equal(pd_tail_5, oml_tail_5) oml_head_4 = oml_tail_5.head(4) pd_head_4 = pd_tail_5.head(4) assert_pandas_opensearch_py_ml_frame_equal(pd_head_4, oml_head_4) def test_head_0(self): oml_flights = self.oml_flights() pd_flights = self.pd_flights() oml_head_0 = oml_flights.head(0) pd_head_0 = pd_flights.head(0) assert_pandas_opensearch_py_ml_frame_equal(pd_head_0, oml_head_0) def test_doc_test_tail(self): df = self.oml_flights() df = df[(df.OriginAirportID == "AMS") & (df.FlightDelayMin > 60)] df = df[["timestamp", "OriginAirportID", "DestAirportID", "FlightDelayMin"]] df = df.tail() print(df) def test_doc_test_tail_empty(self): df = self.oml_flights() df = df[df.OriginAirportID == "NADA"] df = df.tail() assert df.shape[0] == 0 def test_doc_test_tail_single(self): df = self.oml_flights_small() df = df[(df.Carrier == "Kibana Airlines") & (df.DestAirportID == "ITM")].tail() assert df.shape[0] == 1