Skip to content

Commit 9f12619

Browse files
committed
Blacken
1 parent d5418a5 commit 9f12619

File tree

5 files changed

+90
-56
lines changed

5 files changed

+90
-56
lines changed

pandas_select/__init__.py

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,43 @@
44

55
import pandas as pd
66
from pandas.core.accessor import CachedAccessor
7-
from pandas.core.indexes.accessors import (CombinedDatetimelikeProperties,
8-
DatetimeProperties,
9-
PeriodProperties)
7+
from pandas.core.indexes.accessors import (
8+
CombinedDatetimelikeProperties,
9+
DatetimeProperties,
10+
PeriodProperties,
11+
)
1012
from pandas.core.strings import StringMethods
1113
from pandas.util._decorators import doc
1214

13-
_str_boolean_methods = set([
14-
'contains',
15-
'endswith',
16-
'isalnum',
17-
'isalpha',
18-
'isdecimal',
19-
'isdigit',
20-
'islower',
21-
'isnumeric',
22-
'isspace',
23-
'istitle',
24-
'isupper',
25-
'match',
26-
'startswith',
27-
])
28-
29-
_date_boolean_methods = set([
30-
'is_leap_year',
31-
'is_month_end',
32-
'is_month_start',
33-
'is_quarter_end',
34-
'is_quarter_start',
35-
'is_year_end',
36-
'is_year_start',
37-
])
15+
_str_boolean_methods = set(
16+
[
17+
'contains',
18+
'endswith',
19+
'isalnum',
20+
'isalpha',
21+
'isdecimal',
22+
'isdigit',
23+
'islower',
24+
'isnumeric',
25+
'isspace',
26+
'istitle',
27+
'isupper',
28+
'match',
29+
'startswith',
30+
]
31+
)
32+
33+
_date_boolean_methods = set(
34+
[
35+
'is_leap_year',
36+
'is_month_end',
37+
'is_month_start',
38+
'is_quarter_end',
39+
'is_quarter_start',
40+
'is_year_end',
41+
'is_year_start',
42+
]
43+
)
3844

3945

4046
class StringSelectMethods(StringMethods):
@@ -47,11 +53,14 @@ def __init__(self, *args, **kwargs):
4753
super().__init__(self._series, *args[1:], **kwargs)
4854

4955
def __getattribute__(self, attr):
50-
if (not attr.startswith("_") and # noqa
51-
inspect.isroutine(getattr(StringMethods, attr, None))
52-
and attr not in _str_boolean_methods): # noqa
53-
raise NotImplementedError("Boolean selection with this method "
54-
"does not make sense.")
56+
if (
57+
not attr.startswith("_")
58+
and inspect.isroutine(getattr(StringMethods, attr, None)) # noqa
59+
and attr not in _str_boolean_methods
60+
): # noqa
61+
raise NotImplementedError(
62+
"Boolean selection with this method " "does not make sense."
63+
)
5564
else:
5665
return super().__getattribute__(attr)
5766

@@ -69,11 +78,16 @@ def __init__(self, parent, *args, **kwargs):
6978
super().__init__(*args, **kwargs)
7079

7180
def __getattribute__(self, attr):
72-
if (not attr.startswith("_") and # noqa
73-
inspect.isroutine(getattr(DatetimeProperties, attr, None))
74-
and attr not in _date_boolean_methods): # noqa
75-
raise NotImplementedError("Boolean selection with this method "
76-
"does not make sense.")
81+
if (
82+
not attr.startswith("_")
83+
and inspect.isroutine( # noqa
84+
getattr(DatetimeProperties, attr, None)
85+
)
86+
and attr not in _date_boolean_methods
87+
): # noqa
88+
raise NotImplementedError(
89+
"Boolean selection with this method " "does not make sense."
90+
)
7791
elif attr in _date_boolean_methods:
7892
idx = super().__getattribute__(attr)
7993
return self._parent_frame.loc[idx]
@@ -96,17 +110,16 @@ def __new__(cls, series):
96110
properties = super().__new__(cls, series._series)
97111
if isinstance(properties, DatetimeProperties):
98112
return SelectDatetimeProperties(
99-
series._parent,
100-
properties._parent,
101-
properties.orig)
113+
series._parent, properties._parent, properties.orig
114+
)
102115
elif isinstance(properties, PeriodProperties):
103116
return SelectPeriodProperties(
104-
series._frame,
105-
properties._parent,
106-
properties.orig
117+
series._frame, properties._parent, properties.orig
107118
)
108-
raise AttributeError("Can only use select.dt accessor on"
109-
"datetimelike and periodlike values.")
119+
raise AttributeError(
120+
"Can only use select.dt accessor on"
121+
"datetimelike and periodlike values."
122+
)
110123

111124

112125
def selector_wrapper(klass, method_name):
@@ -119,6 +132,7 @@ def selector(self, *args, **kwargs):
119132
series = self._series
120133
idx = getattr(klass, method_name)(series, *args, **kwargs)
121134
return self._parent.loc[idx]
135+
122136
return selector
123137

124138

pandas_select/tests/conftest.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
@pytest.fixture
77
def dta():
8-
return pd.DataFrame.from_dict({
9-
'A': np.arange(1, 16),
10-
'B': pd.date_range('2020-01-01', periods=15),
11-
'C': ['A', 'B', 'C'] * 5,
12-
'D': pd.Categorical(['A', 'B', 'C'] * 5)
13-
})
8+
return pd.DataFrame.from_dict(
9+
{
10+
'A': np.arange(1, 16),
11+
'B': pd.date_range('2020-01-01', periods=15),
12+
'C': ['A', 'B', 'C'] * 5,
13+
'D': pd.Categorical(['A', 'B', 'C'] * 5),
14+
}
15+
)

pandas_select/tests/test_select.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def test_str(dta):
4949
def test_dt(dta):
5050
assert dta.select.B.dt.is_leap_year.equals(dta)
5151
assert len(dta.select.B.dt.is_month_end) == 0
52-
assert (dta.select.B.dt.is_month_start.equals(dta.loc[[0]]))
52+
assert dta.select.B.dt.is_month_start.equals(dta.loc[[0]])
5353
assert len(dta.select.B.dt.is_quarter_end) == 0
54-
assert (dta.select.B.dt.is_quarter_start.equals(dta.loc[[0]]))
54+
assert dta.select.B.dt.is_quarter_start.equals(dta.loc[[0]])
5555
assert len(dta.select.B.dt.is_year_end) == 0
56-
assert (dta.select.B.dt.is_year_start.equals(dta.loc[[0]]))
56+
assert dta.select.B.dt.is_year_start.equals(dta.loc[[0]])
5757

5858

5959
def test_index(dta):

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool.black]
2+
line-length = 79
3+
skip-string-normalization = true
4+
exclude = '''(
5+
/(
6+
\.eggs # exclude a few common directories in the
7+
| \.git # root of the project
8+
| \.hg
9+
| \.mypy_cache
10+
| \.tox
11+
| \.venv
12+
| _build
13+
| buck-out
14+
| build
15+
| dist
16+
)/
17+
)
18+
'''

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
name='pandas_select',
55
version='1.0',
66
description='Add a select accessor to pandas',
7-
packages=['pandas_select']
7+
packages=['pandas_select'],
88
)

0 commit comments

Comments
 (0)