Skip to content

Remove unhittable methods in internals #24594

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 5 commits into from
Jan 3, 2019
Merged
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
66 changes: 5 additions & 61 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
is_re, is_re_compilable, is_sparse, is_timedelta64_dtype, pandas_dtype)
import pandas.core.dtypes.concat as _concat
from pandas.core.dtypes.dtypes import (
CategoricalDtype, DatetimeTZDtype, ExtensionDtype, PandasExtensionDtype)
CategoricalDtype, ExtensionDtype, PandasExtensionDtype)
from pandas.core.dtypes.generic import (
ABCDataFrame, ABCDatetimeIndex, ABCExtensionArray, ABCIndexClass,
ABCSeries)
Expand Down Expand Up @@ -1507,15 +1507,8 @@ def _nanpercentile(values, q, axis, **kw):
len(values)).reshape(len(values),
len(qs))
else:

try:
result = _nanpercentile(values, np.array(qs) * 100,
axis=axis, **kw)
except ValueError:

# older numpies don't handle an array for q
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'm actually just assuming here that the relevant old numpies can by dropped. @h-vetinari any idea on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jbrockmendel

Sorry I was too late too see this. Can't really tell from first glance what's going on, but can have a second look if desired.

result = [_nanpercentile(values, q * 100,
axis=axis, **kw) for q in qs]
result = _nanpercentile(values, np.array(qs) * 100,
axis=axis, **kw)

result = np.array(result, copy=False)
if self.ndim > 1:
Expand Down Expand Up @@ -1639,13 +1632,6 @@ def shape(self):
return (len(self.values)),
return (len(self.mgr_locs), len(self.values))

def get_values(self, dtype=None):
""" need to to_dense myself (and always return a ndim sized object) """
values = self.values.to_dense()
if values.ndim == self.ndim - 1:
values = values.reshape((1,) + values.shape)
return values

def iget(self, col):

if self.ndim == 2 and isinstance(col, tuple):
Expand Down Expand Up @@ -1700,49 +1686,9 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0,
new_values = self._try_coerce_result(new_values)
return [self.make_block(values=new_values)]

def _slice(self, slicer):
""" return a slice of my values (but densify first) """
return self.get_values()[slicer]

def _try_cast_result(self, result, dtype=None):
return result

def _unstack(self, unstacker_func, new_columns, n_rows, fill_value):
Copy link
Member Author

Choose a reason for hiding this comment

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

this and the two methods above are in NonConsolodateableMixin, which is now only mixed in to ExtensionBlock, which directly defines these three methods.

"""Return a list of unstacked blocks of self

Parameters
----------
unstacker_func : callable
Partially applied unstacker.
new_columns : Index
All columns of the unstacked BlockManager.
n_rows : int
Only used in ExtensionBlock.unstack
fill_value : int
Only used in ExtensionBlock.unstack

Returns
-------
blocks : list of Block
New blocks of unstacked values.
mask : array_like of bool
The mask of columns of `blocks` we should keep.
"""
# NonConsolidatable blocks can have a single item only, so we return
# one block per item
unstacker = unstacker_func(self.values.T)

new_placement, new_values, mask = self._get_unstack_items(
unstacker, new_columns
)

new_values = new_values.T[mask]
new_placement = new_placement[mask]

blocks = [self.make_block_same_class(vals, [place])
for vals, place in zip(new_values, new_placement)]
return blocks, mask

def _get_unstack_items(self, unstacker, new_columns):
"""
Get the placement, values, and mask for a Block unstack.
Expand Down Expand Up @@ -2330,11 +2276,11 @@ def to_native_types(self, slicer=None, na_rep=None, date_format=None,
i8values = i8values[..., slicer]

from pandas.io.formats.format import _get_format_datetime64_from_values
format = _get_format_datetime64_from_values(values, date_format)
fmt = _get_format_datetime64_from_values(values, date_format)

result = tslib.format_array_from_datetime(
i8values.ravel(), tz=getattr(self.values, 'tz', None),
format=format, na_rep=na_rep).reshape(i8values.shape)
format=fmt, na_rep=na_rep).reshape(i8values.shape)
return np.atleast_2d(result)

def should_store(self, value):
Expand Down Expand Up @@ -2400,8 +2346,6 @@ def _maybe_coerce_values(self, values, dtype=None):
values = self._holder(values)

if dtype is not None:
if isinstance(dtype, compat.string_types):
dtype = DatetimeTZDtype.construct_from_string(dtype)
Copy link
Member Author

Choose a reason for hiding this comment

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

let the DatetimeArray constructor handle this

values = type(values)(values, dtype=dtype)

if values.tz is None:
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3245,9 +3245,7 @@ def test_setitem(self):
b1 = df._data.blocks[1]
b2 = df._data.blocks[2]
tm.assert_extension_array_equal(b1.values, b2.values)
if b1.values._data.base is not None:
# base being None suffices to assure a copy was made
assert id(b1.values._data.base) != id(b2.values._data.base)
assert id(b1.values._data.base) != id(b2.values._data.base)

# with nan
df2 = df.copy()
Expand Down