10000 Move inconsistent namespace check to pre-commit, fixup more files by MarcoGorelli · Pull Request #37662 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Move inconsistent namespace check to pre-commit, fixup more files #37662

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 17 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
match both directions
  • Loading branch information
MarcoGorelli committed Nov 6, 2020
commit c560facdc75186c1e63d5fc71adb9dfb86d3df54
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def test_infer_dtype_datetime_with_na(self, na_value, time_stamp):
@pytest.mark.parametrize(
"arr",
[
np.array([pd.Timedelta("1 days"), pd.Timedelta("2 days")]),
np.array([Timedelta("1 days"), Timedelta("2 days")]),
np.array([np.timedelta64(1, "D"), np.timedelta64(2, "D")], dtype=object),
np.array([timedelta(1), timedelta(2)]),
],
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def test_groupby_column_index_name_lost_fill_funcs(func):
# GH: 29764 groupby loses index sometimes
df = DataFrame(
[[1, 1.0, -1.0], [1, np.nan, np.nan], [1, 2.0, -2.0]],
columns=pd.Index(["type", "a", "b"], name="idx"),
columns=Index(["type", "a", "b"], name="idx"),
)
df_grouped = df.groupby(["type"])[["a", "b"]]
result = getattr(df_grouped, func)().columns
expected = pd.Index(["a", "b"], name="idx")
expected = Index(["a", "b"], name="idx")
tm.assert_index_equal(result, expected)


Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def test_frame_mixedtype_orient(self): # GH10289
def test_v12_compat(self, datapath):
dti = pd.date_range("2000-01-03", "2000-01-07")
# freq doesnt roundtrip
dti = pd.DatetimeIndex(np.asarray(dti), freq=None)
dti = DatetimeIndex(np.asarray(dti), freq=None)
df = DataFrame(
[
[1.56808523, 0.65727391, 1.81021139, -0.17251653],
Expand Down Expand Up @@ -466,7 +466,7 @@ def test_v12_compat(self, datapath):
def test_blocks_compat_GH9037(self):
index = pd.date_range("20000101", periods=10, freq="H")
# freq doesnt round-trip
index = pd.DatetimeIndex(list(index), freq=None)
index = DatetimeIndex(list(index), freq=None)

df_mixed = DataFrame(
dict(
Expand Down Expand Up @@ -1189,7 +1189,7 @@ def test_tz_range_is_utc(self, tz_range):
)

assert dumps(tz_range, iso_dates=True) == exp
dti = pd.DatetimeIndex(tz_range)
dti = DatetimeIndex(tz_range)
assert dumps(dti, iso_dates=True) == exp
df = DataFrame({"DT": dti})
result = dumps(df, iso_dates=True)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/series/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_getitem_slice_date(self, slc, positions):


class TestSeriesGetitemListLike:
@pytest.mark.parametrize("box", [list, np.array, pd.Index, pd.Series])
@pytest.mark.parametrize("box", [list, np.array, Index, pd.Series])
def test_getitem_no_matches(self, box):
# GH#33462 we expect the same behavior for list/ndarray/Index/Series
ser = Series(["A", "B"])
Expand All @@ -212,7 +212,7 @@ def test_getitem_intlist_intindex_periodvalues(self):
tm.assert_series_equal(result, exp)
assert result.dtype == "Period[D]"

@pytest.mark.parametrize("box", [list, np.array, pd.Index])
@pytest.mark.parametrize("box", [list, np.array, Index])
def test_getitem_intlist_intervalindex_non_int(self, box):
# GH#33404 fall back to positional since ints are unambiguous
dti = date_range("2000-01-03", periods=3)._with_freq(None)
Expand All @@ -224,11 +224,11 @@ def test_getitem_intlist_intervalindex_non_int(self, box):
result = ser[key]
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("box", [list, np.array, pd.Index])
@pytest.mark.parametrize("box", [list, np.array, Index])
@pytest.mark.parametrize("dtype", [np.int64, np.float64, np.uint64])
def test_getitem_intlist_multiindex_numeric_level(self, dtype, box):
# GH#33404 do _not_ fall back to positional since ints are ambiguous
idx = pd.Index(range(4)).astype(dtype)
idx = Index(range(4)).astype(dtype)
dti = date_range("2000-01-03", periods=3)
mi = pd.MultiIndex.from_product([idx, dti])
ser = Series(range(len(mi))[::-1], index=mi)
Expand Down
18 changes: 13 additions & 5 deletions scripts/check_for_inconsistent_pandas_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
import re

PATTERN = r"""
(?<!pd\.)(?<!\w) # check class name doesn't have pd. or a character preceding it
{class_name}\( # match e.g. DataFrame but not pd.DataFrame or tm.makeDataFrame
.* # match anything
pd\.{class_name}\( # only match e.g. pd.DataFrame
(
(?<!pd\.)(?<!\w) # check class_name start with pd. or character
{class_name}\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
.* # match anything
pd\.{class_name}\( # only match e.g. pd.DataFrame
)|
(
pd\.{class_name}\( # only match e.g. pd.DataFrame
.* # match anything
(?<!pd\.)(?<!\w) # check class_name start with pd. or character
{class_name}\( # match DataFrame but not pd.DataFrame or tm.makeDataFrame
)
"""
CLASS_NAMES = (
"Series",
Expand All @@ -38,7 +46,7 @@
for class_name in CLASS_NAMES:
pattern = re.compile(
PATTERN.format(class_name=class_name).encode(),
re.MULTILINE | re.DOTALL | re.VERBOSE,
flags=re.MULTILINE | re.DOTALL | re.VERBOSE,
)
for path in args.paths:
with open(path, "rb") as f:
Expand Down
0