Skip to content
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

CLN16668: remove OrderedDefaultDict #16939

Merged
merged 4 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Removal of prior version deprecations/changes
- ``Categorical`` has dropped the ``.order()`` and ``.sort()`` methods in favor of ``.sort_values()`` (:issue:`12882`)
- :func:`eval` and :method:`DataFrame.eval` have changed the default of ``inplace`` from ``None`` to ``False`` (:issue:`11149`)
- The function ``get_offset_name`` has been dropped in favor of the ``.freqstr`` attribute for an offset (:issue:`11834`)

- The class ``OrderedDefaultDict`` has been removed in favor of ``OrderedDict`` (:issue:`16668`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably can just remove this line. This wasn't part of the documented API.


.. _whatsnew_0210.performance:

Expand Down
25 changes: 0 additions & 25 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
given metaclass instead (and avoids intermediary class creation)

Other items:
* OrderedDefaultDict
* platform checker
"""
# pylint disable=W0611
Expand Down Expand Up @@ -373,30 +372,6 @@ def parse_date(timestr, *args, **kwargs):
parse_date = _date_parser.parse


class OrderedDefaultdict(OrderedDict):

def __init__(self, *args, **kwargs):
newdefault = None
newargs = ()
if args:
newdefault = args[0]
if not (newdefault is None or callable(newdefault)):
raise TypeError('first argument must be callable or None')
newargs = args[1:]
self.default_factory = newdefault
super(self.__class__, self).__init__(*newargs, **kwargs)

def __missing__(self, key):
if self.default_factory is None:
raise KeyError(key)
self[key] = value = self.default_factory()
return value

def __reduce__(self): # optional, for pickle support
args = self.default_factory if self.default_factory else tuple()
return type(self), args, None, None, list(self.items())


# https://github.com/pandas-dev/pandas/pull/9123
def is_platform_little_endian():
""" am I little endian """
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pandas.core.ops as ops
import pandas.core.missing as missing
from pandas import compat
from pandas.compat import (map, zip, range, u, OrderedDict, OrderedDefaultdict)
from pandas.compat import (map, zip, range, u, OrderedDict)
from pandas.compat.numpy import function as nv
from pandas.core.common import _try_sort, _default_index
from pandas.core.frame import DataFrame
Expand Down Expand Up @@ -262,9 +262,11 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None):
"""
orient = orient.lower()
if orient == 'minor':
new_data = OrderedDefaultdict(dict)
new_data = OrderedDict()
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to replace this with new_data = defaultdict(OrderedDict)

for col, df in compat.iteritems(data):
for item, s in compat.iteritems(df):
if item not in new_data:
new_data[item] = {}
new_data[item][col] = s
data = new_data
elif orient != 'items': # pragma: no cover
Expand Down