Skip to content

API: rename pandas/core/generic.py -> pandas/core.ndframe.py #51171

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
Closed
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ repos:
files: ^pandas/
exclude: ^pandas/tests/
types: [python]
- id: no-bool-in-core-generic
name: Use bool_t instead of bool in pandas/core/generic.py
entry: python scripts/no_bool_in_generic.py
- id: no-bool-in-core-ndframe
name: Use bool_t instead of bool in pandas/core/ndframe.py
entry: python scripts/no_bool_in_ndframe.py
language: python
files: ^pandas/core/generic\.py$
files: ^pandas/core/ndframe\.py$
- id: no-return-exception
name: Use raise instead of return for exceptions
language: pygrep
Expand Down
2 changes: 1 addition & 1 deletion pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from pandas.core.arrays.base import ExtensionArray
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame
from pandas.core.groupby.generic import (
DataFrameGroupBy,
GroupBy,
Expand All @@ -63,6 +62,7 @@
SingleArrayManager,
SingleBlockManager,
)
from pandas.core.ndframe import NDFrame
from pandas.core.resample import Resampler
from pandas.core.series import Series
from pandas.core.window.rolling import BaseWindow
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any)
DataFrame,
Series,
)
from pandas.core.generic import NDFrame
from pandas.core.internals import BlockManager
from pandas.core.ndframe import NDFrame

cls = type(self)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
if TYPE_CHECKING:
from pandas._typing import F

from pandas.core.generic import NDFrame
from pandas.core.indexes.api import Index
from pandas.core.ndframe import NDFrame


def _align_core_single_unary_op(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from pandas.core.computation.parsing import tokenize_string
from pandas.core.computation.scope import ensure_scope
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

from pandas.io.formats.printing import pprint_thing

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
PeriodArray,
TimedeltaArray,
)
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame


# define abstract base classes to enable isinstance type checking on our
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
sanitize_array,
sanitize_masked_array,
)
from pandas.core.generic import NDFrame
from pandas.core.indexers import check_key_length
from pandas.core.indexes.api import (
DatetimeIndex,
Expand Down Expand Up @@ -213,6 +212,7 @@
to_arrays,
treat_as_nested,
)
from pandas.core.ndframe import NDFrame
from pandas.core.reshape.melt import melt
from pandas.core.series import Series
from pandas.core.shared_docs import _shared_docs
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
from pandas.plotting import boxplot_frame_groupby

if TYPE_CHECKING:
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

# TODO(typing) the return value on this callable should be any *scalar*.
AggScalar = Union[str, Callable[..., Any]]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class providing the base-class of operations.
)
import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame
from pandas.core.groupby import (
base,
numba_,
Expand All @@ -125,6 +124,7 @@ class providing the base-class of operations.
default_index,
)
from pandas.core.internals.blocks import ensure_block_shape
from pandas.core.ndframe import NDFrame
from pandas.core.series import Series
from pandas.core.sorting import get_group_index_sorter
from pandas.core.util.numba_ import (
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from pandas.io.formats.printing import pprint_thing

if TYPE_CHECKING:
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame


class Grouper:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
)

if TYPE_CHECKING:
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame


class WrappedCythonOp:
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
from pandas.core.apply import ResamplerWindowApply
from pandas.core.base import PandasObject
import pandas.core.common as com
from pandas.core.generic import (
NDFrame,
_shared_docs,
)
from pandas.core.groupby.generic import SeriesGroupBy
from pandas.core.groupby.groupby import (
BaseGroupBy,
Expand All @@ -82,6 +78,10 @@
TimedeltaIndex,
timedelta_range,
)
from pandas.core.ndframe import (
NDFrame,
_shared_docs,
)

from pandas.tseries.frequencies import (
is_subperiod,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
DataFrame,
Series,
)
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

# ---------------------------------------------------------------------
# Concatenate DataFrame objects
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

if TYPE_CHECKING:
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame


def preprocess_weights(obj: NDFrame, weights, axis: AxisInt) -> np.ndarray:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
extract_array,
sanitize_array,
)
from pandas.core.generic import NDFrame
from pandas.core.indexers import (
disallow_ndim_indexing,
unpack_1tuple,
Expand All @@ -156,6 +155,7 @@
SingleArrayManager,
SingleBlockManager,
)
from pandas.core.ndframe import NDFrame
from pandas.core.shared_docs import _shared_docs
from pandas.core.sorting import (
ensure_key_mapped,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if TYPE_CHECKING:
from pandas import DataFrame, Series
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

from pandas.util._decorators import doc

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

if TYPE_CHECKING:
from pandas import DataFrame, Series
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

from pandas.util._decorators import doc

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
DataFrame,
Series,
)
from pandas.core.generic import NDFrame
from pandas.core.groupby.ops import BaseGrouper
from pandas.core.ndframe import NDFrame


class BaseWindow(SelectionMixin):
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
DataFrame,
Series,
)
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame
from pandas.core.shared_docs import _shared_docs

from pandas.io.formats.format import save_to_buffer
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
from pandas.io.parsers.readers import validate_integer

if TYPE_CHECKING:
from pandas.core.generic import NDFrame
from pandas.core.ndframe import NDFrame

FrameSeriesStrT = TypeVar("FrameSeriesStrT", bound=Literal["frame", "series"])

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Check that pandas/core/generic.py doesn't use bool as a type annotation.
Check that pandas/core/ndframe.py doesn't use bool as a type annotation.

There is already the method `bool`, so the alias `bool_t` should be used instead.

This is meant to be run as a pre-commit hook - to run it manually, you can do:

pre-commit run no-bool-in-core-generic --all-files
pre-commit run no-bool-in-core-ndframe --all-files

The function `visit` is adapted from a function by the same name in pyupgrade:
https://github.com/asottile/pyupgrade/blob/5495a248f2165941c5d3b82ac3226ba7ad1fa59d/pyupgrade/_data.py#L70-L113
Expand Down Expand Up @@ -57,7 +57,7 @@ def replace_bool_with_bool_t(to_replace, content: str) -> str:
return "\n".join(new_lines)


def check_for_bool_in_generic(content: str) -> tuple[bool, str]:
def check_for_bool_in_ndframe(content: str) -> tuple[bool, str]:
tree = ast.parse(content)
to_replace = visit(tree)

Expand All @@ -77,7 +77,7 @@ def main(argv: Sequence[str] | None = None) -> None:
for path in args.paths:
with open(path, encoding="utf-8") as fd:
content = fd.read()
mutated, new_content = check_for_bool_in_generic(content)
mutated, new_content = check_for_bool_in_ndframe(content)
if mutated:
with open(path, "w", encoding="utf-8") as fd:
fd.write(new_content)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from scripts.no_bool_in_generic import check_for_bool_in_generic
from scripts.no_bool_in_ndframe import check_for_bool_in_ndframe

BAD_FILE = "def foo(a: bool) -> bool:\n return bool(0)"
GOOD_FILE = "def foo(a: bool_t) -> bool_t:\n return bool(0)"


def test_bad_file_with_replace():
content = BAD_FILE
mutated, result = check_for_bool_in_generic(content)
mutated, result = check_for_bool_in_ndframe(content)
expected = GOOD_FILE
assert result == expected
assert mutated


def test_good_file_with_replace():
content = GOOD_FILE
mutated, result = check_for_bool_in_generic(content)
mutated, result = check_for_bool_in_ndframe(content)
expected = content
assert result == expected
assert not mutated