8000 API: pseudo-public internals API for downstream libraries by jbrockmendel · Pull Request #40182 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

API: pseudo-public internals API for downstream libraries #40182

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 9 commits into from
Mar 5, 2021
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
test
  • Loading branch information
jbrockmendel committed Mar 5, 2021
commit 79a703d9c562bf74872b9caa9cfd61b1044a09ea
12 changes: 9 additions & 3 deletions pandas/core/internals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from pandas.core.internals.api import make_block # pseudo-public version
from pandas.core.internals.array_manager import ArrayManager
from pandas.core.internals.base import DataManager
from pandas.core.internals.blocks import ( # io.pytables
from pandas.core.internals.array_manager import (
ArrayManager,
SingleArrayManager,
)
from pandas.core.internals.base import (
DataManager,
SingleDataManager,
)
from pandas.core.internals.blocks import ( # io.pytables, io.packers
Block,
CategoricalBlock,
DatetimeBlock,
Expand Down
19 changes: 12 additions & 7 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
Index,
ensure_index,
)
from pandas.core.internals.base import DataManager
from pandas.core.internals.base import (
DataManager,
SingleDataManager,
)
from pandas.core.internals.blocks import new_block

T = TypeVar("T", bound="ArrayManager")
Expand Down Expand Up @@ -426,10 +429,14 @@ def apply_with_block(self: T, f, align_keys=None, **kwargs) -> T:
elif arr.dtype.kind == "m" and not isinstance(arr, np.ndarray):
# TimedeltaArray needs to be converted to ndarray for TimedeltaBlock
arr = arr._data # type: ignore[union-attr]
if isinstance(arr, np.ndarray):
arr = np.atleast_2d(arr)

block = new_block(arr, placement=slice(0, 1, 1), ndim=2)
if self.ndim == 2:
if isinstance(arr, np.ndarray):
arr = np.atleast_2d(arr)
block = new_block(arr, placement=slice(0, 1, 1), ndim=2)
else:
block = new_block(arr, placement=slice(0, len(self), 1), ndim=1)

applied = getattr(block, f)(**kwargs)
if isinstance(applied, list):
applied = applied[0]
Expand Down Expand Up @@ -752,9 +759,7 @@ def iget(self, i: int) -> SingleArrayManager:
Return the data as a SingleArrayManager.
"""
values = self.arrays[i]
block = new_block(values, placement=slice(0, len(values)), ndim=1)

return SingleBlockManager(block, self._axes[0])
return SingleArrayManager([values], [self._axes[0]])

def iget_values(self, i: int) -> ArrayLike:
"""
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Tests for the pseudo-public API implemented in internals/api.py and exposed
in core.internals
"""

from pandas.core import internals
from pandas.core.internals import api


Copy link
Contributor

Choose a reason for hiding this comment

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

can you also assert the entire namespace of api itself e.g. [name for name in dir(api) if not name.startswith('_')] and then compare to a hard coded list.

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont think we want to hard-code the existing list bc whats in there is somewhat haphazard. Once we hear back from all the relevant parties on #40226 we'll be able to make that list

Copy link
Contributor

Choose a reason for hiding this comment

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

i would fix it now with all of the symbols that are currently exposed

Copy link
Member Author

Choose a reason for hiding this comment

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

picking my battles; updated.

def test_internals_api():
assert internals.make_block is api.make_block
You are viewing a condensed version of this merge commit. You can view the full changes here.
0