|
8 | 8 | import numpy as np
|
9 | 9 | import pytest
|
10 | 10 |
|
11 |
| -from pandas._libs.tslibs import iNaT |
12 | 11 | from pandas.compat import IS64
|
13 | 12 |
|
14 | 13 | from pandas.core.dtypes.common import (
|
15 | 14 | is_integer_dtype,
|
16 |
| - is_period_dtype, |
17 | 15 | needs_i8_conversion,
|
18 | 16 | )
|
19 | 17 |
|
@@ -173,21 +171,10 @@ def test_unique(self, index_flat):
|
173 | 171 | if not index._can_hold_na:
|
174 | 172 | pytest.skip("Skip na-check if index cannot hold na")
|
175 | 173 |
|
176 |
| - if is_period_dtype(index.dtype): |
177 |
| - vals = index[[0] * 5]._data |
178 |
| - vals[0] = pd.NaT |
179 |
| - elif needs_i8_conversion(index.dtype): |
180 |
| - vals = index._data._ndarray[[0] * 5] |
181 |
| - vals[0] = iNaT |
182 |
| - else: |
183 |
| - vals = index.values[[0] * 5] |
184 |
| - vals[0] = np.nan |
| 174 | + vals = index._values[[0] * 5] |
| 175 | + vals[0] = np.nan |
185 | 176 |
|
186 | 177 | vals_unique = vals[:2]
|
187 |
| - if index.dtype.kind in ["m", "M"]: |
188 |
| - # i.e. needs_i8_conversion but not period_dtype, as above |
189 |
| - vals = type(index._data)(vals, dtype=index.dtype) |
190 |
| - vals_unique = type(index._data)._simple_new(vals_unique, dtype=index.dtype) |
191 | 178 | idx_nan = index._shallow_copy(vals)
|
192 | 179 | idx_unique_nan = index._shallow_copy(vals_unique)
|
193 | 180 | assert idx_unique_nan.is_unique is True
|
@@ -378,26 +365,21 @@ def test_hasnans_isnans(self, index_flat):
|
378 | 365 | assert idx.hasnans is False
|
379 | 366 |
|
380 | 367 | idx = index.copy(deep=True)
|
381 |
| - values = np.asarray(idx.values) |
| 368 | + values = idx._values |
382 | 369 |
|
383 | 370 | if len(index) == 0:
|
384 | 371 | return
|
385 | 372 | elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype):
|
386 | 373 | return
|
387 |
| - elif needs_i8_conversion(index.dtype): |
388 |
| - values[1] = iNaT |
389 |
| - else: |
390 |
| - values[1] = np.nan |
391 | 374 |
|
392 |
| - if isinstance(index, PeriodIndex): |
393 |
| - idx = type(index)(values, freq=index.freq) |
394 |
| - else: |
395 |
| - idx = type(index)(values) |
| 375 | + values[1] = np.nan |
396 | 376 |
|
397 |
| - expected = np.array([False] * len(idx), dtype=bool) |
398 |
| - expected[1] = True |
399 |
| - tm.assert_numpy_array_equal(idx._isnan, expected) |
400 |
| - assert idx.hasnans is True |
| 377 | + idx = type(index)(values) |
| 378 | + |
| 379 | + expected = np.array([False] * len(idx), dtype=bool) |
| 380 | + expected[1] = True |
| 381 | + tm.assert_numpy_array_equal(idx._isnan, expected) |
| 382 | + assert idx.hasnans is True |
401 | 383 |
|
402 | 384 |
|
403 | 385 | @pytest.mark.parametrize("na_position", [None, "middle"])
|
|
0 commit comments