Skip to content

Commit 9e0d87d

Browse files
committed
update docs, cleanup
1 parent 1271d3d commit 9e0d87d

File tree

6 files changed

+11
-15
lines changed

6 files changed

+11
-15
lines changed

doc/source/whatsnew/v0.24.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,6 @@ update the ``ExtensionDtype._metadata`` tuple to match the signature of your
994994
- :meth:`Series.astype` and :meth:`DataFrame.astype` now dispatch to :meth:`ExtensionArray.astype` (:issue:`21185:`).
995995
- Slicing a single row of a ``DataFrame`` with multiple ExtensionArrays of the same type now preserves the dtype, rather than coercing to object (:issue:`22784`)
996996
- Added :meth:`pandas.api.types.register_extension_dtype` to register an extension type with pandas (:issue:`22664`)
997-
- Added :meth:`pandas.api.extensions.ExtensionArray.where` (:issue:`24077`)
998997
- Bug when concatenating multiple ``Series`` with different extension dtypes not casting to object dtype (:issue:`22994`)
999998
- Series backed by an ``ExtensionArray`` now work with :func:`util.hash_pandas_object` (:issue:`23066`)
1000999
- Updated the ``.type`` attribute for ``PeriodDtype``, ``DatetimeTZDtype``, and ``IntervalDtype`` to be instances of the dtype (``Period``, ``Timestamp``, and ``Interval`` respectively) (:issue:`22938`)

pandas/core/arrays/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class ExtensionArray(object):
6464
* unique
6565
* factorize / _values_for_factorize
6666
* argsort / _values_for_argsort
67-
* where
6867
6968
The remaining methods implemented on this class should be performant,
7069
as they only compose abstract methods. Still, a more efficient
@@ -221,6 +220,8 @@ def __setitem__(self, key, value):
221220
# example, a string like '2018-01-01' is coerced to a datetime
222221
# when setting on a datetime64ns array. In general, if the
223222
# __init__ method coerces that value, then so should __setitem__
223+
# Note, also, that Series/DataFrame.where internally use __setitem__
224+
# on a copy of the data.
224225
raise NotImplementedError(_not_implemented_message.format(
225226
type(self), '__setitem__')
226227
)

pandas/core/arrays/period.py

-5
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ def _generate_range(cls, start, end, periods, freq, fields):
241241

242242
return subarr, freq
243243

244-
def _check_compatible_with(self, other):
245-
if self.freqstr != other.freqstr:
246-
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
247-
raise IncompatibleFrequency(msg)
248-
249244
# --------------------------------------------------------------------
250245
# Data / Attributes
251246

pandas/core/dtypes/base.py

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class _DtypeOpsMixin(object):
2626
na_value = np.nan
2727
_metadata = ()
2828

29-
@property
30-
def _ndarray_na_value(self):
31-
"""Private method internal to pandas"""
32-
raise AbstractMethodError(self)
33-
3429
def __eq__(self, other):
3530
"""Check whether 'other' is equal to self.
3631

pandas/core/indexes/category.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,14 @@ def _can_reindex(self, indexer):
501501

502502
@Appender(_index_shared_docs['where'])
503503
def where(self, cond, other=None):
504-
cat = self.values.where(cond, other=other)
504+
# TODO: Investigate an alternative implementation with
505+
# 1. copy the underyling Categorical
506+
# 2. setitem with `cond` and `other`
507+
# 3. Rebuild CategoricalIndex.
508+
if other is None:
509+
other = self._na_value
510+
values = np.where(cond, self.values, other)
511+
cat = Categorical(values, dtype=self.dtype)
505512
return self._shallow_copy(cat, **self._get_attributes_dict())
506513

507514
def reindex(self, target, method=None, level=None, limit=None,

pandas/core/internals/blocks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,6 @@ def shift(self, periods, axis=0):
19701970

19711971
def where(self, other, cond, align=True, errors='raise',
19721972
try_cast=False, axis=0, transpose=False):
1973-
# rough attempt to see if
19741973
if isinstance(other, (ABCIndexClass, ABCSeries)):
19751974
other = other.array
19761975

@@ -2004,8 +2003,8 @@ def where(self, other, cond, align=True, errors='raise',
20042003
else:
20052004
dtype = self.dtype
20062005

2006+
# rough heuristic to see if the other array implements setitem
20072007
if self._holder.__setitem__ is ExtensionArray.__setitem__:
2008-
# the array doesn't implement setitem, so convert to ndarray
20092008
result = self._holder._from_sequence(
20102009
np.where(cond, self.values, other),
20112010
dtype=dtype,

0 commit comments

Comments
 (0)