Skip to content

Commit 2fe0c48

Browse files
committed
docstrings, remove need for swapaxes
1 parent 1d6b812 commit 2fe0c48

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

pandas/core/arrays/base.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,14 @@ class ReshapeMixin:
11281128
11291129
Subclass must implement _wrap_data property.
11301130
1131-
NB: we assume that the constructor will accept:
1132-
1131+
Notes
1132+
-----
1133+
- We assume that the constructor will accept:
11331134
type(self)(self._wrap_data.reshape(shape), dtype=self.dtype)
1134-
1135-
If not, then the methods below will need to be overriden.
1135+
If not, then the methods below will need to be overriden.
1136+
- We assume that the only 2D shapes taken will be (N, 1) and (1, N).
1137+
This ensures that we can reshape, transpose, and ravel without worrying
1138+
about column-order/row-order.
11361139
"""
11371140

11381141
@property
@@ -1178,10 +1181,3 @@ def T(self):
11781181
def ravel(self, order=None):
11791182
data = self._wrap_data.ravel(order=order)
11801183
return type(self)(data, dtype=self.dtype)
1181-
1182-
def swapaxes(self, axis1, axis2): # TODO: needs test
1183-
data = self._wrap_data.swapaxes(axis1, axis2)
1184-
return type(self)(data, dtype=self.dtype)
1185-
1186-
# TODO: Squeeze
1187-
# TODO: comments about reshape/ravel order

pandas/core/arrays/datetimelike.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ def astype(self, dtype, copy=True):
539539
dtype = pandas_dtype(dtype)
540540

541541
if is_object_dtype(dtype):
542-
# TODO: Do we need to worry about order for ravel/reshape?
543542
return self._box_values(self.asi8.ravel()).reshape(self.shape)
544543
elif is_string_dtype(dtype) and not is_categorical_dtype(dtype):
545544
return self._format_native_types()

pandas/core/groupby/ops.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,7 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1,
476476
if axis > 0:
477477
swapped = True
478478
assert axis == 1, axis
479-
# TODO: can we just use values.T here?
480-
# i.e. will axis ever by greater than 1?
481-
values = values.swapaxes(0, axis)
479+
values = values.T
482480
if arity > 1:
483481
raise NotImplementedError("arity of more than 1 is not "
484482
"supported for the 'how' argument")

pandas/core/internals/blocks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ def replace(self, to_replace, value, inplace=False, filter=None,
744744
mask[filtered_out.nonzero()[0]] = False
745745

746746
if not mask.any():
747-
# TODO: is this the right copy semantics?
748747
if convert:
749748
# NB: this check must come before the "if inplace" check
750749
out = self.convert(by_item=True, numeric=False,
@@ -804,7 +803,7 @@ def setitem(self, indexer, value):
804803
if self.is_numeric:
805804
value = np.nan
806805

807-
# TODO: For each DatetimeTZBlock can we just call values__setitem__ directly?
806+
# TODO: For DatetimeTZBlock can we call values.__setitem__ directly?
808807
# coerce if block dtype can store value
809808
values = self.values
810809
try:
@@ -1431,7 +1430,6 @@ def quantile(self, qs, interpolation='linear', axis=0):
14311430
# but `Block.get_values()` returns an ndarray of objects
14321431
# right now. We need an API for "values to do numeric-like ops on"
14331432
values = self.values.asi8
1434-
# TODO: is the above still needed?
14351433
else:
14361434
values = self.get_values()
14371435
values, _ = self._try_coerce_args(values, values)
@@ -3156,7 +3154,11 @@ def _block_shape(values, ndim=1, shape=None):
31563154
if values.ndim < ndim:
31573155
if shape is None:
31583156
shape = values.shape
3159-
if not is_extension_array_dtype(values):
3157+
if isinstance(values, ABCDatetimeIndex):
3158+
# DatetimeArray can be reshaped; DatetimeIndex cannot
3159+
values = values._data
3160+
if (not is_extension_array_dtype(values)
3161+
or is_datetime64tz_dtype(values)):
31603162
# TODO: https://github.com/pandas-dev/pandas/issues/23023
31613163
# block.shape is incorrect for "2D" ExtensionArrays
31623164
# We can't, and don't need to, reshape.

0 commit comments

Comments
 (0)