|
5 | 5 |
|
6 | 6 | from pandas.core.dtypes.common import is_scalar
|
7 | 7 |
|
8 |
| -import pandas as pd |
9 |
| -from pandas import DataFrame, Series, date_range |
| 8 | +from pandas import DataFrame, Series |
10 | 9 | import pandas._testing as tm
|
11 | 10 |
|
12 | 11 | # ----------------------------------------------------------------------
|
@@ -248,31 +247,6 @@ def test_metadata_propagation(self):
|
248 | 247 | self.check_metadata(v1 & v2)
|
249 | 248 | self.check_metadata(v1 | v2)
|
250 | 249 |
|
251 |
| - def test_head_tail(self, index): |
252 |
| - # GH5370 |
253 |
| - |
254 |
| - o = self._construct(shape=len(index)) |
255 |
| - |
256 |
| - axis = o._get_axis_name(0) |
257 |
| - setattr(o, axis, index) |
258 |
| - |
259 |
| - o.head() |
260 |
| - |
261 |
| - self._compare(o.head(), o.iloc[:5]) |
262 |
| - self._compare(o.tail(), o.iloc[-5:]) |
263 |
| - |
264 |
| - # 0-len |
265 |
| - self._compare(o.head(0), o.iloc[0:0]) |
266 |
| - self._compare(o.tail(0), o.iloc[0:0]) |
267 |
| - |
268 |
| - # bounded |
269 |
| - self._compare(o.head(len(o) + 1), o) |
270 |
| - self._compare(o.tail(len(o) + 1), o) |
271 |
| - |
272 |
| - # neg index |
273 |
| - self._compare(o.head(-3), o.head(len(index) - 3)) |
274 |
| - self._compare(o.tail(-3), o.tail(len(index) - 3)) |
275 |
| - |
276 | 250 | def test_size_compat(self):
|
277 | 251 | # GH8846
|
278 | 252 | # size property should be defined
|
@@ -460,102 +434,47 @@ def test_take_invalid_kwargs(self):
|
460 | 434 | obj.take(indices, mode="clip")
|
461 | 435 |
|
462 | 436 | @pytest.mark.parametrize("is_copy", [True, False])
|
463 |
| - def test_depr_take_kwarg_is_copy(self, is_copy): |
| 437 | + def test_depr_take_kwarg_is_copy(self, is_copy, frame_or_series): |
464 | 438 | # GH 27357
|
465 |
| - df = DataFrame({"A": [1, 2, 3]}) |
| 439 | + obj = DataFrame({"A": [1, 2, 3]}) |
| 440 | + if frame_or_series is Series: |
| 441 | + obj = obj["A"] |
| 442 | + |
466 | 443 | msg = (
|
467 | 444 | "is_copy is deprecated and will be removed in a future version. "
|
468 | 445 | "'take' always returns a copy, so there is no need to specify this."
|
469 | 446 | )
|
470 | 447 | with tm.assert_produces_warning(FutureWarning) as w:
|
471 |
| - df.take([0, 1], is_copy=is_copy) |
| 448 | + obj.take([0, 1], is_copy=is_copy) |
472 | 449 |
|
473 | 450 | assert w[0].message.args[0] == msg
|
474 | 451 |
|
475 |
| - s = Series([1, 2, 3]) |
476 |
| - with tm.assert_produces_warning(FutureWarning): |
477 |
| - s.take([0, 1], is_copy=is_copy) |
478 |
| - |
479 |
| - def test_equals(self): |
480 |
| - # Add object dtype column with nans |
481 |
| - index = np.random.random(10) |
482 |
| - df1 = DataFrame(np.random.random(10), index=index, columns=["floats"]) |
483 |
| - df1["text"] = "the sky is so blue. we could use more chocolate.".split() |
484 |
| - df1["start"] = date_range("2000-1-1", periods=10, freq="T") |
485 |
| - df1["end"] = date_range("2000-1-1", periods=10, freq="D") |
486 |
| - df1["diff"] = df1["end"] - df1["start"] |
487 |
| - df1["bool"] = np.arange(10) % 3 == 0 |
488 |
| - df1.loc[::2] = np.nan |
489 |
| - df2 = df1.copy() |
490 |
| - assert df1["text"].equals(df2["text"]) |
491 |
| - assert df1["start"].equals(df2["start"]) |
492 |
| - assert df1["end"].equals(df2["end"]) |
493 |
| - assert df1["diff"].equals(df2["diff"]) |
494 |
| - assert df1["bool"].equals(df2["bool"]) |
495 |
| - assert df1.equals(df2) |
496 |
| - assert not df1.equals(object) |
497 |
| - |
498 |
| - # different dtype |
499 |
| - different = df1.copy() |
500 |
| - different["floats"] = different["floats"].astype("float32") |
501 |
| - assert not df1.equals(different) |
502 |
| - |
503 |
| - # different index |
504 |
| - different_index = -index |
505 |
| - different = df2.set_index(different_index) |
506 |
| - assert not df1.equals(different) |
507 |
| - |
508 |
| - # different columns |
509 |
| - different = df2.copy() |
510 |
| - different.columns = df2.columns[::-1] |
511 |
| - assert not df1.equals(different) |
512 |
| - |
513 |
| - # DatetimeIndex |
514 |
| - index = pd.date_range("2000-1-1", periods=10, freq="T") |
515 |
| - df1 = df1.set_index(index) |
516 |
| - df2 = df1.copy() |
517 |
| - assert df1.equals(df2) |
518 |
| - |
519 |
| - # MultiIndex |
520 |
| - df3 = df1.set_index(["text"], append=True) |
521 |
| - df2 = df1.set_index(["text"], append=True) |
522 |
| - assert df3.equals(df2) |
523 |
| - |
524 |
| - df2 = df1.set_index(["floats"], append=True) |
525 |
| - assert not df3.equals(df2) |
526 |
| - |
527 |
| - # NaN in index |
528 |
| - df3 = df1.set_index(["floats"], append=True) |
529 |
| - df2 = df1.set_index(["floats"], append=True) |
530 |
| - assert df3.equals(df2) |
531 |
| - |
532 |
| - @pytest.mark.parametrize("box", [pd.Series, pd.DataFrame]) |
533 |
| - def test_axis_classmethods(self, box): |
| 452 | + def test_axis_classmethods(self, frame_or_series): |
| 453 | + box = frame_or_series |
534 | 454 | obj = box(dtype=object)
|
535 | 455 | values = box._AXIS_TO_AXIS_NUMBER.keys()
|
536 | 456 | for v in values:
|
537 | 457 | assert obj._get_axis_number(v) == box._get_axis_number(v)
|
538 | 458 | assert obj._get_axis_name(v) == box._get_axis_name(v)
|
539 | 459 | assert obj._get_block_manager_axis(v) == box._get_block_manager_axis(v)
|
540 | 460 |
|
541 |
| - @pytest.mark.parametrize("box", [pd.Series, pd.DataFrame]) |
542 |
| - def test_axis_names_deprecated(self, box): |
| 461 | + def test_axis_names_deprecated(self, frame_or_series): |
543 | 462 | # GH33637
|
| 463 | + box = frame_or_series |
544 | 464 | obj = box(dtype=object)
|
545 | 465 | with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
|
546 | 466 | obj._AXIS_NAMES
|
547 | 467 |
|
548 |
| - @pytest.mark.parametrize("box", [pd.Series, pd.DataFrame]) |
549 |
| - def test_axis_numbers_deprecated(self, box): |
| 468 | + def test_axis_numbers_deprecated(self, frame_or_series): |
550 | 469 | # GH33637
|
| 470 | + box = frame_or_series |
551 | 471 | obj = box(dtype=object)
|
552 | 472 | with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
|
553 | 473 | obj._AXIS_NUMBERS
|
554 | 474 |
|
555 |
| - @pytest.mark.parametrize("as_frame", [True, False]) |
556 |
| - def test_flags_identity(self, as_frame): |
| 475 | + def test_flags_identity(self, frame_or_series): |
557 | 476 | s = Series([1, 2])
|
558 |
| - if as_frame: |
| 477 | + if frame_or_series is DataFrame: |
559 | 478 | s = s.to_frame()
|
560 | 479 |
|
561 | 480 | assert s.flags is s.flags
|
|
0 commit comments