""" Generated by RIMI """ import sys import traceback passed = 0 failed = 0 skipped = 0 def test(name, func): global passed, failed, skipped try: result = func() if isinstance(result, str) and result == "SKIP": skipped += 1 print(f" SKIP #{passed+failed+skipped:02d} {name}") else: passed += 1 print(f" OK #{passed+failed+skipped:02d} {name}") except Exception as e: failed += 1 print(f" FAIL #{passed+failed+skipped:02d} {name}: {e}") traceback.print_exc() print("=" * 60) print("pandas 2.3.3 — Android norelro test") print("Python", sys.version) print("=" * 60) # 1. import pandas test("import pandas", lambda: __import__("pandas")) # 2. version check test("pandas.__version__", lambda: None if __import__("pandas").__version__ == "2.3.3" else (_ for _ in ()).throw(Exception(f"wrong version"))) # 3. import numpy (bundled dep) test("import numpy (bundled dep)", lambda: __import__("numpy")) # 4. DataFrame basics test("DataFrame create", lambda: __import__("pandas").DataFrame({"a": [1, 2], "b": [3, 4]})) # 5. DataFrame shape def test_shape(): import pandas as pd df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) assert df.shape == (3, 2), f"wrong shape: {df.shape}" test("DataFrame shape", test_shape) # 6. DataFrame head/tail def test_head_tail(): import pandas as pd df = pd.DataFrame({"x": range(100)}) assert len(df.head(5)) == 5 assert len(df.tail(5)) == 5 test("DataFrame head/tail", test_head_tail) # 7. DataFrame dtypes def test_dtypes(): import pandas as pd df = pd.DataFrame({"a": [1, 2], "b": [1.0, 2.0], "c": ["x", "y"]}) assert df.dtypes["a"].name == "int64" assert df.dtypes["b"].name == "float64" assert df.dtypes["c"].name == "object" test("DataFrame dtypes", test_dtypes) # 8. DataFrame describe def test_describe(): import pandas as pd df = pd.DataFrame({"a": [1, 2, 3, 4, 5]}) desc = df.describe() assert desc.loc["mean", "a"] == 3.0 test("DataFrame describe", test_describe) # 9. DataFrame groupby def test_groupby(): import pandas as pd df = pd.DataFrame({"g": ["a", "a", "b"], "v": [1, 2, 3]}) result = df.groupby("g")["v"].sum() assert result["a"] == 3 assert result["b"] == 3 test("DataFrame groupby", test_groupby) # 10. DataFrame sort def test_sort(): import pandas as pd df = pd.DataFrame({"a": [3, 1, 2]}) df_sorted = df.sort_values("a") assert list(df_sorted["a"]) == [1, 2, 3] test("DataFrame sort_values", test_sort) # 11. DataFrame apply def test_apply(): import pandas as pd df = pd.DataFrame({"a": [1, 2, 3]}) result = df["a"].apply(lambda x: x * 2) assert list(result) == [2, 4, 6] test("DataFrame apply", test_apply) # 12. DataFrame merge def test_merge(): import pandas as pd a = pd.DataFrame({"k": [1, 2], "v": ["a", "b"]}) b = pd.DataFrame({"k": [1, 2], "w": ["c", "d"]}) m = a.merge(b, on="k") assert list(m.columns) == ["k", "v", "w"] assert len(m) == 2 test("DataFrame merge", test_merge) # 13. DataFrame concat def test_concat(): import pandas as pd a = pd.DataFrame({"a": [1, 2]}) b = pd.DataFrame({"a": [3, 4]}) c = pd.concat([a, b], ignore_index=True) assert list(c["a"]) == [1, 2, 3, 4] test("DataFrame concat", test_concat) # 14. DataFrame fillna/dropna def test_fillna(): import pandas as pd df = pd.DataFrame({"a": [1, None, 3]}) filled = df.fillna(0) assert list(filled["a"]) == [1.0, 0.0, 3.0] dropped = df.dropna() assert len(dropped) == 2 test("DataFrame fillna/dropna", test_fillna) # 15. DataFrame pivot def test_pivot(): import pandas as pd df = pd.DataFrame({"r": ["a", "a"], "c": ["x", "y"], "v": [1, 2]}) p = df.pivot(index="r", columns="c", values="v") assert p.loc["a", "x"] == 1 assert p.loc["a", "y"] == 2 test("DataFrame pivot", test_pivot) # 16. DataFrame melt def test_melt(): import pandas as pd df = pd.DataFrame({"id": [1], "x": [2], "y": [3]}) m = pd.melt(df, id_vars=["id"]) assert len(m) == 2 test("DataFrame melt", test_melt) # 17. Series operations def test_series(): import pandas as pd s = pd.Series([1, 2, 3, 4]) assert s.sum() == 10 assert s.mean() == 2.5 assert s.max() == 4 assert s.min() == 1 test("Series agg ops", test_series) # 18. DatetimeIndex def test_datetime(): import pandas as pd dates = pd.date_range("2024-01-01", periods=5, freq="D") assert len(dates) == 5 assert dates[0].year == 2024 assert dates[0].month == 1 assert dates[0].day == 1 test("DatetimeIndex", test_datetime) # 19. Timedelta def test_timedelta(): import pandas as pd td = pd.Timedelta("1 day 2 hours") assert td.total_seconds() == 93600.0 test("Timedelta", test_timedelta) # 20. read_csv / to_csv roundtrip def test_csv(): import pandas as pd, os, tempfile df = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]}) with tempfile.NamedTemporaryFile(suffix=".csv", delete=False, mode="w") as f: df.to_csv(f, index=False) tmp = f.name df2 = pd.read_csv(tmp) os.unlink(tmp) assert list(df2["a"]) == [1, 2, 3] assert list(df2["b"]) == ["x", "y", "z"] test("read_csv / to_csv roundtrip", test_csv) # 21. read_json / to_json roundtrip def test_json(): import pandas as pd, os, tempfile df = pd.DataFrame({"a": [1, 2], "b": [3.0, 4.0]}) with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as f: df.to_json(f, orient="records") tmp = f.name df2 = pd.read_json(tmp, orient="records") os.unlink(tmp) assert list(df2["a"]) == [1, 2] test("read_json / to_json roundtrip", test_json) # 22. DataFrame value_counts def test_value_counts(): import pandas as pd s = pd.Series(["a", "b", "a", "a", "b"]) vc = s.value_counts() assert vc["a"] == 3 assert vc["b"] == 2 test("Series value_counts", test_value_counts) # 23. DataFrame corr def test_corr(): import pandas as pd df = pd.DataFrame({"a": [1, 2, 3], "b": [2, 4, 6]}) corr = df["a"].corr(df["b"]) assert abs(corr - 1.0) < 1e-10 test("DataFrame corr", test_corr) # 24. DataFrame map/replace def test_replace(): import pandas as pd s = pd.Series([1, 2, 3]) r = s.replace({1: "a", 2: "b", 3: "c"}) assert list(r) == ["a", "b", "c"] test("Series replace", test_replace) # 25. MultiIndex def test_multiindex(): import pandas as pd arrays = [["a", "a", "b", "b"], [1, 2, 1, 2]] idx = pd.MultiIndex.from_arrays(arrays, names=["l1", "l2"]) df = pd.DataFrame({"v": [10, 20, 30, 40]}, index=idx) assert df.loc["a", 1].iloc[0] == 10 test("MultiIndex", test_multiindex) # 26. DataFrame to_numpy def test_to_numpy(): import pandas as pd df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) arr = df.to_numpy() assert arr.shape == (2, 2) assert arr[0, 0] == 1 assert arr[1, 1] == 4 test("DataFrame to_numpy", test_to_numpy) # 27. Categorical def test_categorical(): import pandas as pd s = pd.Categorical(["a", "b", "a", "c"]) assert len(s) == 4 assert s.categories.tolist() == ["a", "b", "c"] test("Categorical", test_categorical) # 28. DataFrame assign def test_assign(): import pandas as pd df = pd.DataFrame({"a": [1, 2]}) df2 = df.assign(b=df["a"] * 10) assert list(df2["b"]) == [10, 20] test("DataFrame assign", test_assign) # 29. DataFrame pipe def test_pipe(): import pandas as pd df = pd.DataFrame({"a": [1, 2, 3]}) def add_one(data): return data.assign(b=data["a"] + 1) df2 = df.pipe(add_one) assert list(df2["b"]) == [2, 3, 4] test("DataFrame pipe", test_pipe) # 30. DataFrame nunique/nlargest def test_nlargest(): import pandas as pd df = pd.DataFrame({"a": [10, 1, 5, 20, 3]}) top = df.nlargest(2, "a") assert list(top["a"]) == [20, 10] test("DataFrame nlargest", test_nlargest) print() print("=" * 60) print(f"RESULT: {passed} PASS, {failed} FAIL, {skipped} SKIP") print("=" * 60) if failed > 0: sys.exit(1)