Skip to content

TST: method-specific file for to_period #32270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions pandas/tests/series/methods/test_to_period.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import numpy as np

from pandas import (
DataFrame,
DatetimeIndex,
PeriodIndex,
Series,
date_range,
period_range,
)
import pandas._testing as tm


class TestToPeriod:
def test_to_period(self):
rng = date_range("1/1/2000", "1/1/2001", freq="D")
ts = Series(np.random.randn(len(rng)), index=rng)

pts = ts.to_period()
exp = ts.copy()
exp.index = period_range("1/1/2000", "1/1/2001")
tm.assert_series_equal(pts, exp)

pts = ts.to_period("M")
exp.index = exp.index.asfreq("M")
tm.assert_index_equal(pts.index, exp.index.asfreq("M"))
tm.assert_series_equal(pts, exp)

# GH#7606 without freq
idx = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"])
exp_idx = PeriodIndex(
["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"], freq="D"
)

s = Series(np.random.randn(4), index=idx)
expected = s.copy()
expected.index = exp_idx
tm.assert_series_equal(s.to_period(), expected)

df = DataFrame(np.random.randn(4, 4), index=idx, columns=idx)
expected = df.copy()
expected.index = exp_idx
tm.assert_frame_equal(df.to_period(), expected)

expected = df.copy()
expected.columns = exp_idx
tm.assert_frame_equal(df.to_period(axis=1), expected)
35 changes: 0 additions & 35 deletions pandas/tests/series/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,41 +309,6 @@ def test_format_pre_1900_dates(self):
ts = Series(1, index=rng)
repr(ts)

def test_to_period(self):
from pandas.core.indexes.period import period_range

ts = _simple_ts("1/1/2000", "1/1/2001")

pts = ts.to_period()
exp = ts.copy()
exp.index = period_range("1/1/2000", "1/1/2001")
tm.assert_series_equal(pts, exp)

pts = ts.to_period("M")
exp.index = exp.index.asfreq("M")
tm.assert_index_equal(pts.index, exp.index.asfreq("M"))
tm.assert_series_equal(pts, exp)

# GH 7606 without freq
idx = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"])
exp_idx = pd.PeriodIndex(
["2011-01-01", "2011-01-02", "2011-01-03", "2011-01-04"], freq="D"
)

s = Series(np.random.randn(4), index=idx)
expected = s.copy()
expected.index = exp_idx
tm.assert_series_equal(s.to_period(), expected)

df = DataFrame(np.random.randn(4, 4), index=idx, columns=idx)
expected = df.copy()
expected.index = exp_idx
tm.assert_frame_equal(df.to_period(), expected)

expected = df.copy()
expected.columns = exp_idx
tm.assert_frame_equal(df.to_period(axis=1), expected)

def test_groupby_count_dateparseerror(self):
dr = date_range(start="1/1/2012", freq="5min", periods=10)

Expand Down