Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_align.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_asof.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_assign.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_astype.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_clip.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_combine_first.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_compare.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_convert_dtypes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_copy.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_cov_corr.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_describe.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_droplevel.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_dropna.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_dtypes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_duplicated.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_fillna.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_filter.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_first_valid_index.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_get_numeric_data.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_head_tail.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_interpolate.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_is_homogeneous_dtype.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_isetitem.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_isin.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_join.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_map.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_matmul.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_pct_change.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rank.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_reindex.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rename.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rename_axis.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_reorder_levels.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_round.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_select_dtypes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_set_axis.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_set_index.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_size.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_sort_index.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_swaplevel.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_csv.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_period.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_records.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_truncate.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_update.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_value_counts.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_values.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/test_add_prefix_suffix.py +49 -0
- llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/test_asfreq.py +263 -0
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (433 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_align.cpython-310.pyc
ADDED
Binary file (14 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_asof.cpython-310.pyc
ADDED
Binary file (5.35 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_assign.cpython-310.pyc
ADDED
Binary file (3.81 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_astype.cpython-310.pyc
ADDED
Binary file (27 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_clip.cpython-310.pyc
ADDED
Binary file (6.57 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_combine_first.cpython-310.pyc
ADDED
Binary file (15.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_compare.cpython-310.pyc
ADDED
Binary file (6.78 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_convert_dtypes.cpython-310.pyc
ADDED
Binary file (6.57 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_copy.cpython-310.pyc
ADDED
Binary file (2.08 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_cov_corr.cpython-310.pyc
ADDED
Binary file (15.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_describe.cpython-310.pyc
ADDED
Binary file (11.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_droplevel.cpython-310.pyc
ADDED
Binary file (1.33 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_dropna.cpython-310.pyc
ADDED
Binary file (9.03 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_dtypes.cpython-310.pyc
ADDED
Binary file (5.02 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_duplicated.cpython-310.pyc
ADDED
Binary file (3.04 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_fillna.cpython-310.pyc
ADDED
Binary file (26.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_filter.cpython-310.pyc
ADDED
Binary file (4.82 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_first_valid_index.cpython-310.pyc
ADDED
Binary file (3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_get_numeric_data.cpython-310.pyc
ADDED
Binary file (3.11 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_head_tail.cpython-310.pyc
ADDED
Binary file (1.74 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_interpolate.cpython-310.pyc
ADDED
Binary file (16.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_is_homogeneous_dtype.cpython-310.pyc
ADDED
Binary file (1.02 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_isetitem.cpython-310.pyc
ADDED
Binary file (1.86 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_isin.cpython-310.pyc
ADDED
Binary file (7.24 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_join.cpython-310.pyc
ADDED
Binary file (14.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_map.cpython-310.pyc
ADDED
Binary file (7.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_matmul.cpython-310.pyc
ADDED
Binary file (2.31 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_pct_change.cpython-310.pyc
ADDED
Binary file (5.23 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rank.cpython-310.pyc
ADDED
Binary file (12.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_reindex.cpython-310.pyc
ADDED
Binary file (36 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rename.cpython-310.pyc
ADDED
Binary file (11.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_rename_axis.cpython-310.pyc
ADDED
Binary file (3.65 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_reorder_levels.cpython-310.pyc
ADDED
Binary file (2.33 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_round.cpython-310.pyc
ADDED
Binary file (6.14 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_select_dtypes.cpython-310.pyc
ADDED
Binary file (14.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_set_axis.cpython-310.pyc
ADDED
Binary file (4.81 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_set_index.cpython-310.pyc
ADDED
Binary file (21.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_size.cpython-310.pyc
ADDED
Binary file (781 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_sort_index.cpython-310.pyc
ADDED
Binary file (25.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_swaplevel.cpython-310.pyc
ADDED
Binary file (1.31 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_csv.cpython-310.pyc
ADDED
Binary file (42.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_period.cpython-310.pyc
ADDED
Binary file (3.05 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_to_records.cpython-310.pyc
ADDED
Binary file (11.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_truncate.cpython-310.pyc
ADDED
Binary file (4.98 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_update.cpython-310.pyc
ADDED
Binary file (6.82 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_value_counts.cpython-310.pyc
ADDED
Binary file (4.68 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/__pycache__/test_values.cpython-310.pyc
ADDED
Binary file (7.64 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/test_add_prefix_suffix.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest
|
2 |
+
|
3 |
+
from pandas import Index
|
4 |
+
import pandas._testing as tm
|
5 |
+
|
6 |
+
|
7 |
+
def test_add_prefix_suffix(float_frame):
|
8 |
+
with_prefix = float_frame.add_prefix("foo#")
|
9 |
+
expected = Index([f"foo#{c}" for c in float_frame.columns])
|
10 |
+
tm.assert_index_equal(with_prefix.columns, expected)
|
11 |
+
|
12 |
+
with_suffix = float_frame.add_suffix("#foo")
|
13 |
+
expected = Index([f"{c}#foo" for c in float_frame.columns])
|
14 |
+
tm.assert_index_equal(with_suffix.columns, expected)
|
15 |
+
|
16 |
+
with_pct_prefix = float_frame.add_prefix("%")
|
17 |
+
expected = Index([f"%{c}" for c in float_frame.columns])
|
18 |
+
tm.assert_index_equal(with_pct_prefix.columns, expected)
|
19 |
+
|
20 |
+
with_pct_suffix = float_frame.add_suffix("%")
|
21 |
+
expected = Index([f"{c}%" for c in float_frame.columns])
|
22 |
+
tm.assert_index_equal(with_pct_suffix.columns, expected)
|
23 |
+
|
24 |
+
|
25 |
+
def test_add_prefix_suffix_axis(float_frame):
|
26 |
+
# GH 47819
|
27 |
+
with_prefix = float_frame.add_prefix("foo#", axis=0)
|
28 |
+
expected = Index([f"foo#{c}" for c in float_frame.index])
|
29 |
+
tm.assert_index_equal(with_prefix.index, expected)
|
30 |
+
|
31 |
+
with_prefix = float_frame.add_prefix("foo#", axis=1)
|
32 |
+
expected = Index([f"foo#{c}" for c in float_frame.columns])
|
33 |
+
tm.assert_index_equal(with_prefix.columns, expected)
|
34 |
+
|
35 |
+
with_pct_suffix = float_frame.add_suffix("#foo", axis=0)
|
36 |
+
expected = Index([f"{c}#foo" for c in float_frame.index])
|
37 |
+
tm.assert_index_equal(with_pct_suffix.index, expected)
|
38 |
+
|
39 |
+
with_pct_suffix = float_frame.add_suffix("#foo", axis=1)
|
40 |
+
expected = Index([f"{c}#foo" for c in float_frame.columns])
|
41 |
+
tm.assert_index_equal(with_pct_suffix.columns, expected)
|
42 |
+
|
43 |
+
|
44 |
+
def test_add_prefix_suffix_invalid_axis(float_frame):
|
45 |
+
with pytest.raises(ValueError, match="No axis named 2 for object type DataFrame"):
|
46 |
+
float_frame.add_prefix("foo#", axis=2)
|
47 |
+
|
48 |
+
with pytest.raises(ValueError, match="No axis named 2 for object type DataFrame"):
|
49 |
+
float_frame.add_suffix("foo#", axis=2)
|
llmeval-env/lib/python3.10/site-packages/pandas/tests/frame/methods/test_asfreq.py
ADDED
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datetime import datetime
|
2 |
+
|
3 |
+
import numpy as np
|
4 |
+
import pytest
|
5 |
+
|
6 |
+
from pandas._libs.tslibs.offsets import MonthEnd
|
7 |
+
|
8 |
+
from pandas import (
|
9 |
+
DataFrame,
|
10 |
+
DatetimeIndex,
|
11 |
+
Series,
|
12 |
+
date_range,
|
13 |
+
period_range,
|
14 |
+
to_datetime,
|
15 |
+
)
|
16 |
+
import pandas._testing as tm
|
17 |
+
|
18 |
+
from pandas.tseries import offsets
|
19 |
+
|
20 |
+
|
21 |
+
class TestAsFreq:
|
22 |
+
@pytest.fixture(params=["s", "ms", "us", "ns"])
|
23 |
+
def unit(self, request):
|
24 |
+
return request.param
|
25 |
+
|
26 |
+
def test_asfreq2(self, frame_or_series):
|
27 |
+
ts = frame_or_series(
|
28 |
+
[0.0, 1.0, 2.0],
|
29 |
+
index=DatetimeIndex(
|
30 |
+
[
|
31 |
+
datetime(2009, 10, 30),
|
32 |
+
datetime(2009, 11, 30),
|
33 |
+
datetime(2009, 12, 31),
|
34 |
+
],
|
35 |
+
dtype="M8[ns]",
|
36 |
+
freq="BME",
|
37 |
+
),
|
38 |
+
)
|
39 |
+
|
40 |
+
daily_ts = ts.asfreq("B")
|
41 |
+
monthly_ts = daily_ts.asfreq("BME")
|
42 |
+
tm.assert_equal(monthly_ts, ts)
|
43 |
+
|
44 |
+
daily_ts = ts.asfreq("B", method="pad")
|
45 |
+
monthly_ts = daily_ts.asfreq("BME")
|
46 |
+
tm.assert_equal(monthly_ts, ts)
|
47 |
+
|
48 |
+
daily_ts = ts.asfreq(offsets.BDay())
|
49 |
+
monthly_ts = daily_ts.asfreq(offsets.BMonthEnd())
|
50 |
+
tm.assert_equal(monthly_ts, ts)
|
51 |
+
|
52 |
+
result = ts[:0].asfreq("ME")
|
53 |
+
assert len(result) == 0
|
54 |
+
assert result is not ts
|
55 |
+
|
56 |
+
if frame_or_series is Series:
|
57 |
+
daily_ts = ts.asfreq("D", fill_value=-1)
|
58 |
+
result = daily_ts.value_counts().sort_index()
|
59 |
+
expected = Series(
|
60 |
+
[60, 1, 1, 1], index=[-1.0, 2.0, 1.0, 0.0], name="count"
|
61 |
+
).sort_index()
|
62 |
+
tm.assert_series_equal(result, expected)
|
63 |
+
|
64 |
+
def test_asfreq_datetimeindex_empty(self, frame_or_series):
|
65 |
+
# GH#14320
|
66 |
+
index = DatetimeIndex(["2016-09-29 11:00"])
|
67 |
+
expected = frame_or_series(index=index, dtype=object).asfreq("h")
|
68 |
+
result = frame_or_series([3], index=index.copy()).asfreq("h")
|
69 |
+
tm.assert_index_equal(expected.index, result.index)
|
70 |
+
|
71 |
+
@pytest.mark.parametrize("tz", ["US/Eastern", "dateutil/US/Eastern"])
|
72 |
+
def test_tz_aware_asfreq_smoke(self, tz, frame_or_series):
|
73 |
+
dr = date_range("2011-12-01", "2012-07-20", freq="D", tz=tz)
|
74 |
+
|
75 |
+
obj = frame_or_series(
|
76 |
+
np.random.default_rng(2).standard_normal(len(dr)), index=dr
|
77 |
+
)
|
78 |
+
|
79 |
+
# it works!
|
80 |
+
obj.asfreq("min")
|
81 |
+
|
82 |
+
def test_asfreq_normalize(self, frame_or_series):
|
83 |
+
rng = date_range("1/1/2000 09:30", periods=20)
|
84 |
+
norm = date_range("1/1/2000", periods=20)
|
85 |
+
|
86 |
+
vals = np.random.default_rng(2).standard_normal((20, 3))
|
87 |
+
|
88 |
+
obj = DataFrame(vals, index=rng)
|
89 |
+
expected = DataFrame(vals, index=norm)
|
90 |
+
if frame_or_series is Series:
|
91 |
+
obj = obj[0]
|
92 |
+
expected = expected[0]
|
93 |
+
|
94 |
+
result = obj.asfreq("D", normalize=True)
|
95 |
+
tm.assert_equal(result, expected)
|
96 |
+
|
97 |
+
def test_asfreq_keep_index_name(self, frame_or_series):
|
98 |
+
# GH#9854
|
99 |
+
index_name = "bar"
|
100 |
+
index = date_range("20130101", periods=20, name=index_name)
|
101 |
+
obj = DataFrame(list(range(20)), columns=["foo"], index=index)
|
102 |
+
obj = tm.get_obj(obj, frame_or_series)
|
103 |
+
|
104 |
+
assert index_name == obj.index.name
|
105 |
+
assert index_name == obj.asfreq("10D").index.name
|
106 |
+
|
107 |
+
def test_asfreq_ts(self, frame_or_series):
|
108 |
+
index = period_range(freq="Y", start="1/1/2001", end="12/31/2010")
|
109 |
+
obj = DataFrame(
|
110 |
+
np.random.default_rng(2).standard_normal((len(index), 3)), index=index
|
111 |
+
)
|
112 |
+
obj = tm.get_obj(obj, frame_or_series)
|
113 |
+
|
114 |
+
result = obj.asfreq("D", how="end")
|
115 |
+
exp_index = index.asfreq("D", how="end")
|
116 |
+
assert len(result) == len(obj)
|
117 |
+
tm.assert_index_equal(result.index, exp_index)
|
118 |
+
|
119 |
+
result = obj.asfreq("D", how="start")
|
120 |
+
exp_index = index.asfreq("D", how="start")
|
121 |
+
assert len(result) == len(obj)
|
122 |
+
tm.assert_index_equal(result.index, exp_index)
|
123 |
+
|
124 |
+
def test_asfreq_resample_set_correct_freq(self, frame_or_series):
|
125 |
+
# GH#5613
|
126 |
+
# we test if .asfreq() and .resample() set the correct value for .freq
|
127 |
+
dti = to_datetime(["2012-01-01", "2012-01-02", "2012-01-03"])
|
128 |
+
obj = DataFrame({"col": [1, 2, 3]}, index=dti)
|
129 |
+
obj = tm.get_obj(obj, frame_or_series)
|
130 |
+
|
131 |
+
# testing the settings before calling .asfreq() and .resample()
|
132 |
+
assert obj.index.freq is None
|
133 |
+
assert obj.index.inferred_freq == "D"
|
134 |
+
|
135 |
+
# does .asfreq() set .freq correctly?
|
136 |
+
assert obj.asfreq("D").index.freq == "D"
|
137 |
+
|
138 |
+
# does .resample() set .freq correctly?
|
139 |
+
assert obj.resample("D").asfreq().index.freq == "D"
|
140 |
+
|
141 |
+
def test_asfreq_empty(self, datetime_frame):
|
142 |
+
# test does not blow up on length-0 DataFrame
|
143 |
+
zero_length = datetime_frame.reindex([])
|
144 |
+
result = zero_length.asfreq("BME")
|
145 |
+
assert result is not zero_length
|
146 |
+
|
147 |
+
def test_asfreq(self, datetime_frame):
|
148 |
+
offset_monthly = datetime_frame.asfreq(offsets.BMonthEnd())
|
149 |
+
rule_monthly = datetime_frame.asfreq("BME")
|
150 |
+
|
151 |
+
tm.assert_frame_equal(offset_monthly, rule_monthly)
|
152 |
+
|
153 |
+
rule_monthly.asfreq("B", method="pad")
|
154 |
+
# TODO: actually check that this worked.
|
155 |
+
|
156 |
+
# don't forget!
|
157 |
+
rule_monthly.asfreq("B", method="pad")
|
158 |
+
|
159 |
+
def test_asfreq_datetimeindex(self):
|
160 |
+
df = DataFrame(
|
161 |
+
{"A": [1, 2, 3]},
|
162 |
+
index=[datetime(2011, 11, 1), datetime(2011, 11, 2), datetime(2011, 11, 3)],
|
163 |
+
)
|
164 |
+
df = df.asfreq("B")
|
165 |
+
assert isinstance(df.index, DatetimeIndex)
|
166 |
+
|
167 |
+
ts = df["A"].asfreq("B")
|
168 |
+
assert isinstance(ts.index, DatetimeIndex)
|
169 |
+
|
170 |
+
def test_asfreq_fillvalue(self):
|
171 |
+
# test for fill value during upsampling, related to issue 3715
|
172 |
+
|
173 |
+
# setup
|
174 |
+
rng = date_range("1/1/2016", periods=10, freq="2s")
|
175 |
+
# Explicit cast to 'float' to avoid implicit cast when setting None
|
176 |
+
ts = Series(np.arange(len(rng)), index=rng, dtype="float")
|
177 |
+
df = DataFrame({"one": ts})
|
178 |
+
|
179 |
+
# insert pre-existing missing value
|
180 |
+
df.loc["2016-01-01 00:00:08", "one"] = None
|
181 |
+
|
182 |
+
actual_df = df.asfreq(freq="1s", fill_value=9.0)
|
183 |
+
expected_df = df.asfreq(freq="1s").fillna(9.0)
|
184 |
+
expected_df.loc["2016-01-01 00:00:08", "one"] = None
|
185 |
+
tm.assert_frame_equal(expected_df, actual_df)
|
186 |
+
|
187 |
+
expected_series = ts.asfreq(freq="1s").fillna(9.0)
|
188 |
+
actual_series = ts.asfreq(freq="1s", fill_value=9.0)
|
189 |
+
tm.assert_series_equal(expected_series, actual_series)
|
190 |
+
|
191 |
+
def test_asfreq_with_date_object_index(self, frame_or_series):
|
192 |
+
rng = date_range("1/1/2000", periods=20)
|
193 |
+
ts = frame_or_series(np.random.default_rng(2).standard_normal(20), index=rng)
|
194 |
+
|
195 |
+
ts2 = ts.copy()
|
196 |
+
ts2.index = [x.date() for x in ts2.index]
|
197 |
+
|
198 |
+
result = ts2.asfreq("4h", method="ffill")
|
199 |
+
expected = ts.asfreq("4h", method="ffill")
|
200 |
+
tm.assert_equal(result, expected)
|
201 |
+
|
202 |
+
def test_asfreq_with_unsorted_index(self, frame_or_series):
|
203 |
+
# GH#39805
|
204 |
+
# Test that rows are not dropped when the datetime index is out of order
|
205 |
+
index = to_datetime(["2021-01-04", "2021-01-02", "2021-01-03", "2021-01-01"])
|
206 |
+
result = frame_or_series(range(4), index=index)
|
207 |
+
|
208 |
+
expected = result.reindex(sorted(index))
|
209 |
+
expected.index = expected.index._with_freq("infer")
|
210 |
+
|
211 |
+
result = result.asfreq("D")
|
212 |
+
tm.assert_equal(result, expected)
|
213 |
+
|
214 |
+
def test_asfreq_after_normalize(self, unit):
|
215 |
+
# https://github.com/pandas-dev/pandas/issues/50727
|
216 |
+
result = DatetimeIndex(
|
217 |
+
date_range("2000", periods=2).as_unit(unit).normalize(), freq="D"
|
218 |
+
)
|
219 |
+
expected = DatetimeIndex(["2000-01-01", "2000-01-02"], freq="D").as_unit(unit)
|
220 |
+
tm.assert_index_equal(result, expected)
|
221 |
+
|
222 |
+
@pytest.mark.parametrize(
|
223 |
+
"freq, freq_half",
|
224 |
+
[
|
225 |
+
("2ME", "ME"),
|
226 |
+
(MonthEnd(2), MonthEnd(1)),
|
227 |
+
],
|
228 |
+
)
|
229 |
+
def test_asfreq_2ME(self, freq, freq_half):
|
230 |
+
index = date_range("1/1/2000", periods=6, freq=freq_half)
|
231 |
+
df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0, 4.0, 5.0], index=index)})
|
232 |
+
expected = df.asfreq(freq=freq)
|
233 |
+
|
234 |
+
index = date_range("1/1/2000", periods=3, freq=freq)
|
235 |
+
result = DataFrame({"s": Series([0.0, 2.0, 4.0], index=index)})
|
236 |
+
tm.assert_frame_equal(result, expected)
|
237 |
+
|
238 |
+
@pytest.mark.parametrize(
|
239 |
+
"freq, freq_depr",
|
240 |
+
[
|
241 |
+
("2ME", "2M"),
|
242 |
+
("2QE", "2Q"),
|
243 |
+
("2QE-SEP", "2Q-SEP"),
|
244 |
+
("1BQE", "1BQ"),
|
245 |
+
("2BQE-SEP", "2BQ-SEP"),
|
246 |
+
("1YE", "1Y"),
|
247 |
+
("2YE-MAR", "2Y-MAR"),
|
248 |
+
("1YE", "1A"),
|
249 |
+
("2YE-MAR", "2A-MAR"),
|
250 |
+
("2BYE-MAR", "2BA-MAR"),
|
251 |
+
],
|
252 |
+
)
|
253 |
+
def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
|
254 |
+
# GH#9586, #55978
|
255 |
+
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
|
256 |
+
f"in a future version, please use '{freq[1:]}' instead."
|
257 |
+
|
258 |
+
index = date_range("1/1/2000", periods=4, freq=f"{freq[1:]}")
|
259 |
+
df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)})
|
260 |
+
expected = df.asfreq(freq=freq)
|
261 |
+
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
|
262 |
+
result = df.asfreq(freq=freq_depr)
|
263 |
+
tm.assert_frame_equal(result, expected)
|