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

switch internal instances of collections.OrderedDict to regular dict #3030

Merged
merged 1 commit into from Jan 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions doc/source/cookbook/simulation_analysis.py
@@ -1,5 +1,3 @@
import collections

import yt

yt.enable_parallelism()
Expand Down Expand Up @@ -27,13 +25,13 @@
# Fill the dictionary with extrema and redshift information for each dataset
data[ds.basename] = (extrema, ds.current_redshift)

# Convert dictionary to ordered dictionary to get the right order
od = collections.OrderedDict(sorted(data.items()))
# Sort dict by keys
data = {k: v for k, v in sorted(data.items())}

# Print out all the values we calculated.
print("Dataset Redshift Density Min Density Max")
print("---------------------------------------------------------")
for key, val in od.items():
for key, val in data.items():
print(
"%s %05.3f %5.3g g/cm^3 %5.3g g/cm^3"
% (key, val[1], val[0][0], val[0][1])
Expand Down
3 changes: 0 additions & 3 deletions yt/data_objects/particle_trajectories.py
@@ -1,5 +1,3 @@
from collections import OrderedDict

import numpy as np

from yt.config import ytcfg
Expand Down Expand Up @@ -69,7 +67,6 @@ def __init__(

if fields is None:
fields = []
fields = list(OrderedDict.fromkeys(fields))
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 may not look obvious but the current implementation here is actually doing nothing, so I went with the option of preserving behaviour rather than intent. I think the original intent was to sort the keys, in which case it should be simply reimplemented as

fields = sorted(keys)

@jzuhone , do you remember this ? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine. I also think that someone came in here and did this later, because I don't recognize the code to be honest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, thanks for your prompt answer


if self.suppress_logging:
old_level = int(ytcfg.get("yt", "loglevel"))
Expand Down
4 changes: 1 addition & 3 deletions yt/data_objects/profiles.py
Expand Up @@ -597,12 +597,10 @@ def to_dataframe(self, fields=None, only_used=False):
>>> df1 = p.to_dataframe()
>>> df2 = p.to_dataframe(fields="density", only_used=True)
"""
from collections import OrderedDict

import pandas as pd

idxs, masked, fields = self._export_prep(fields, only_used)
pdata = OrderedDict([(self.x_field[-1], self.x[idxs])])
pdata = {self.x_field[-1]: self.x[idxs]}
for field in fields:
pdata[field[-1]] = self[field][idxs]
df = pd.DataFrame(pdata)
Expand Down