Skip to content

TST: split tests for windows to sub-modules #19667

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bf59983
documentação
giba0 Feb 12, 2018
2a49a9a
Revert "documentação"
giba0 Feb 12, 2018
a6a5e96
Merge branch 'master' into upstream/master
giba0 Feb 12, 2018
f235163
Merge remote-tracking branch 'origin/master'
giba0 Feb 12, 2018
55b2661
Merge branch 'master' into upstream/master
giba0 Feb 12, 2018
1785d61
Creating the window folder and the files test_rolling.py, test_expand…
giba0 Feb 12, 2018
b9c121d
Inclusion of tests for the rolling functions according to the file te…
giba0 Feb 12, 2018
018685b
Inclusion of tests for the expanding functions according to the test_…
giba0 Feb 12, 2018
3cef534
Inclusion of tests for the ewma functions according to the test_windo…
giba0 Feb 12, 2018
9cb7a4f
Correcting file formatting.
giba0 Feb 12, 2018
9a4469e
Merge branch 'master' of https://github.com/pandas-dev/pandas
giba0 Feb 12, 2018
52db43a
Merge branch 'master' into TST--split-tests-for-windows-to-sub-module…
giba0 Feb 12, 2018
375c68d
Merge branch 'TST--split-tests-for-windows-to-sub-modules-#19228'
giba0 Feb 12, 2018
8414a1f
Ambiguity correction in documentation on pandas.DataFrame.to_parquet
giba0 Feb 12, 2018
229c9c1
Merge branch 'DOCS---Ambiguous-description-in-pandas.DataFrame.to_par…
giba0 Feb 12, 2018
2962a8f
documentação
giba0 Feb 12, 2018
4544afa
Revert "documentação"
giba0 Feb 12, 2018
ccf473f
Creating the window folder and the files test_rolling.py, test_expand…
giba0 Feb 12, 2018
95d9d0e
Inclusion of tests for the rolling functions according to the file te…
giba0 Feb 12, 2018
e65af3b
Inclusion of tests for the expanding functions according to the test_…
giba0 Feb 12, 2018
a3abbb9
Inclusion of tests for the ewma functions according to the test_windo…
giba0 Feb 12, 2018
af463bb
Correcting file formatting.
giba0 Feb 12, 2018
6f74164
Ambiguity correction in documentation on pandas.DataFrame.to_parquet
giba0 Feb 12, 2018
5ca693a
Revert "documentação"
giba0 Feb 13, 2018
ac0f751
Revert "Revert "documentação""
giba0 Feb 13, 2018
a8c0b01
Merge branch 'split-tests'
giba0 Feb 13, 2018
9b99bf8
Merge branch 'master' into split-tests
giba0 Feb 13, 2018
5fb9885
Merge remote-tracking branch 'origin/master'
giba0 Feb 13, 2018
9778aa9
Merge remote-tracking branch 'upstream/master'
giba0 Feb 15, 2018
39e9292
Merge remote-tracking branch 'upstream/master' into TST--split-tests-…
giba0 Feb 17, 2018
02de0d7
Merge remote-tracking branch 'origin/master'
giba0 Feb 17, 2018
05b00be
Merge branch 'TST--split-tests-for-windows-to-sub-modules-#19228'
giba0 Feb 17, 2018
7343a88
Merge branch 'master' into PR_TOOL_MERGE_PR_19667
jreback Feb 18, 2018
8ee74d9
Merge branch 'master' of https://github.com/pandas-dev/pandas
giba0 Feb 24, 2018
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
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ def _ensure_valid_index(self, value):
if not len(self.index) and is_list_like(value):
try:
value = Series(value)
except:
except ValueError:
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')
Expand Down
Empty file.
97 changes: 97 additions & 0 deletions pandas/tests/windows/test_ewma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from datetime import datetime

import numpy as np
import pytest
from numpy.random import randn

import pandas.core.window as rwindow
import pandas.util.testing as tm
from pandas import DataFrame, Series, bdate_range
from pandas.errors import UnsupportedFunctionCall

N, K = 100, 10


def assert_equal(left, right):
if isinstance(left, Series):
tm.assert_series_equal(left, right)
else:
tm.assert_frame_equal(left, right)


class Base(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below


_nan_locs = np.arange(20, 40)
_inf_locs = np.array([])

def _create_data(self):
arr = randn(N)
arr[self._nan_locs] = np.NaN

self.arr = arr
self.rng = bdate_range(datetime(2009, 1, 1), periods=N)
self.series = Series(arr.copy(), index=self.rng)
self.frame = DataFrame(randn(N, K), index=self.rng,
columns=np.arange(K))


class TestEWM(Base):

def setup_method(self, method):
self._create_data()

def test_doc_string(self):

df = DataFrame({'B': [0, 1, 2, np.nan, 4]})
df
df.ewm(com=0.5).mean()

def test_constructor(self):
for o in [self.series, self.frame]:
c = o.ewm

# valid
c(com=0.5)
c(span=1.5)
c(alpha=0.5)
c(halflife=0.75)
c(com=0.5, span=None)
c(alpha=0.5, com=None)
c(halflife=0.75, alpha=None)

# not valid: mutually exclusive
with pytest.raises(ValueError):
c(com=0.5, alpha=0.5)
with pytest.raises(ValueError):
c(span=1.5, halflife=0.75)
with pytest.raises(ValueError):
c(alpha=0.5, span=1.5)

# not valid: com < 0
with pytest.raises(ValueError):
c(com=-0.5)

# not valid: span < 1
with pytest.raises(ValueError):
c(span=0.5)

# not valid: halflife <= 0
with pytest.raises(ValueError):
c(halflife=0)

# not valid: alpha <= 0 or alpha > 1
for alpha in (-0.5, 1.5):
with pytest.raises(ValueError):
c(alpha=alpha)

def test_numpy_compat(self):
# see gh-12811
e = rwindow.EWM(Series([2, 4, 6]), alpha=0.5)

msg = "numpy operations are not valid with window objects"

for func in ('std', 'mean', 'var'):
tm.assert_raises_regex(UnsupportedFunctionCall, msg,
getattr(e, func), 1, 2, 3)
tm.assert_raises_regex(UnsupportedFunctionCall, msg,
getattr(e, func), dtype=np.float64)
111 changes: 111 additions & 0 deletions pandas/tests/windows/test_expanding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from datetime import datetime

import numpy as np
import pytest
from numpy.random import randn

import pandas as pd
import pandas.core.window as rwindow
import pandas.util.testing as tm
from pandas import DataFrame, Series, bdate_range
from pandas.errors import UnsupportedFunctionCall

N, K = 100, 10


def assert_equal(left, right):
if isinstance(left, Series):
tm.assert_series_equal(left, right)
else:
tm.assert_frame_equal(left, right)


class Base(object):

_nan_locs = np.arange(20, 40)
_inf_locs = np.array([])

def _create_data(self):
arr = randn(N)
arr[self._nan_locs] = np.NaN

self.arr = arr
self.rng = bdate_range(datetime(2009, 1, 1), periods=N)
self.series = Series(arr.copy(), index=self.rng)
self.frame = DataFrame(randn(N, K), index=self.rng,
columns=np.arange(K))


class TestExpanding(Base):

def setup_method(self, method):
self._create_data()

def test_doc_string(self):

df = DataFrame({'B': [0, 1, 2, np.nan, 4]})
df
df.expanding(2).sum()

def test_constructor(self):
# GH 12669

for o in [self.series, self.frame]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a fixture for series and frame (in conftest.py)

c = o.expanding

# valid
c(min_periods=1)
c(min_periods=1, center=True)
c(min_periods=1, center=False)

# not valid
for w in [2., 'foo', np.array([2])]:
with pytest.raises(ValueError):
c(min_periods=w)
with pytest.raises(ValueError):
c(min_periods=1, center=w)

def test_numpy_compat(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameterize this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you hlep me? Here I need use a decorator @pytest.mark.parametrize?

# see gh-12811
e = rwindow.Expanding(Series([2, 4, 6]), window=2)

msg = "numpy operations are not valid with window objects"

for func in ('std', 'mean', 'sum', 'max', 'min', 'var'):
tm.assert_raises_regex(UnsupportedFunctionCall, msg,
getattr(e, func), 1, 2, 3)
tm.assert_raises_regex(UnsupportedFunctionCall, msg,
getattr(e, func), dtype=np.float64)

@pytest.mark.parametrize(
'expander',
[1, pytest.param('ls', marks=pytest.mark.xfail(
reason='GH 16425 expanding with '
'offset not supported'))])
def test_empty_df_expanding(self, expander):
# GH 15819 Verifies that datetime and integer expanding windows can be
# applied to empty DataFrames

expected = DataFrame()
result = DataFrame().expanding(expander).sum()
tm.assert_frame_equal(result, expected)

# Verifies that datetime and integer expanding windows can be applied
# to empty DataFrames with datetime index
expected = DataFrame(index=pd.DatetimeIndex([]))
result = DataFrame(
index=pd.DatetimeIndex([])).expanding(expander).sum()
tm.assert_frame_equal(result, expected)

def test_missing_minp_zero(self):
# https://github.com/pandas-dev/pandas/pull/18921
# minp=0
x = pd.Series([np.nan])
result = x.expanding(min_periods=0).sum()
expected = pd.Series([0.0])
tm.assert_series_equal(result, expected)

# minp=1
result = x.expanding(min_periods=1).sum()
expected = pd.Series([np.nan])
tm.assert_series_equal(result, expected)
Loading