| Server IP : 209.209.40.120 / Your IP : 216.73.217.112 Web Server : Microsoft-IIS/10.0 System : Windows NT NEWWWW 10.0 build 17763 (Windows Server 2019) i586 User : NEWWWW$ ( 0) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Python312/Lib/site-packages/pandas/tests/frame/methods/ |
Upload File : |
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
other = float_frame.reindex(index=float_frame.index[:10], columns=["C", "B"])
tm.assert_frame_equal(other, float_frame.reindex_like(other))
@pytest.mark.parametrize(
"method,expected_values",
[
("nearest", [0, 1, 1, 2]),
("pad", [np.nan, 0, 1, 1]),
("backfill", [0, 1, 2, 2]),
],
)
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)
def test_reindex_like_subclass(self):
# https://github.com/pandas-dev/pandas/issues/31925
class MyDataFrame(DataFrame):
pass
expected = DataFrame()
df = MyDataFrame()
result = df.reindex_like(expected)
tm.assert_frame_equal(result, expected)