コード例 #1
0
ファイル: test_indexes.py プロジェクト: mathause/xarray
    def test_concat_periods(self):
        periods = pd.period_range("2000-01-01", periods=10)
        indexes = [PandasIndex(periods[:5], "t"), PandasIndex(periods[5:], "t")]
        expected = PandasIndex(periods, "t")
        actual = PandasIndex.concat(indexes, dim="t")
        assert actual.equals(expected)
        assert isinstance(actual.index, pd.PeriodIndex)

        positions = [list(range(5)), list(range(5, 10))]
        actual = PandasIndex.concat(indexes, dim="t", positions=positions)
        assert actual.equals(expected)
        assert isinstance(actual.index, pd.PeriodIndex)
コード例 #2
0
    def test_concat_str_dtype(self, dtype) -> None:

        a = PandasIndex(np.array(["a"], dtype=dtype), "x", coord_dtype=dtype)
        b = PandasIndex(np.array(["b"], dtype=dtype), "x", coord_dtype=dtype)
        expected = PandasIndex(np.array(["a", "b"], dtype=dtype),
                               "x",
                               coord_dtype=dtype)

        actual = PandasIndex.concat([a, b], "x")
        assert actual.equals(expected)
        assert np.issubdtype(actual.coord_dtype, dtype)
コード例 #3
0
    def test_concat_dim_error(self) -> None:
        indexes = [PandasIndex([0, 1], "x"), PandasIndex([2, 3], "y")]

        with pytest.raises(ValueError,
                           match=r"Cannot concatenate.*dimensions.*"):
            PandasIndex.concat(indexes, "x")
コード例 #4
0
 def test_concat_empty(self) -> None:
     idx = PandasIndex.concat([], "x")
     assert idx.coord_dtype is np.dtype("O")