Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Maybe a small bug in yaml.dump #4

Closed
XiongweiWu opened this issue Jan 23, 2018 · 5 comments
Closed

Maybe a small bug in yaml.dump #4

XiongweiWu opened this issue Jan 23, 2018 · 5 comments

Comments

@XiongweiWu
Copy link

XiongweiWu commented Jan 23, 2018

Hi thx for your excellent work. I notice a small bug when running your code in my side. When save cfg file using yaml (

yaml.dump(cfg, stream=f)
,
cfg_yaml = yaml.dump(cfg)
) , cfg.PIXEL_MEANS should transfer its type from array to list to my understanding, otherwise, a bug reports. Maybe u can check it.

@rbgirshick
Copy link
Contributor

@XiongweiWu: perhaps I don't understand the concern, but this should be fine as the type information will be embedded in the yaml.

E.g., this passes:

import numpy as np
import yaml

assert type(yaml.load(yaml.dump(dict(foo=np.array([1,2,3]))))['foo']) == np.ndarray

Also see:

print(yaml.dump(dict(foo=np.array([1,2,3]))))

Outputs:

foo: !!python/object/apply:numpy.core.multiarray._reconstruct
  args:
  - !!python/name:numpy.ndarray ''
  - !!python/tuple [0]
  - b
  state: !!python/tuple
  - 1
  - !!python/tuple [3]
  - !!python/object/apply:numpy.dtype
    args: [i8, 0, 1]
    state: !!python/tuple [3, <, null, null, null, -1, -1, 0]
  - false
  - "\x01\0\0\0\0\0\0\0\x02\0\0\0\0\0\0\0\x03\0\0\0\0\0\0\0"

@XiongweiWu
Copy link
Author

@rbgirshick In my side this command reports errors(print(yaml.dump(dict(foo=np.array([1,2,3]))))). Which numpy and yaml version are u using?

@ir413
Copy link
Contributor

ir413 commented Jan 23, 2018

@XiongweiWu: We use numpy version 1.13 and yaml version 3.12. We will update the installation instructions with this information.

@zyqfrog10
Copy link

zyqfrog10 commented Jul 19, 2019

Hi @rbgirshick @ir413 ,

I have the same issue after yaml.update and yaml.safe_dump. The information contained in the generated .yaml file can not be interpreted by other tools like multiqc.
Is there a solution? Thank you.

By the way, I am using python3.6, numpy 1.14.5 and yaml 5.1.
-A

@zyqfrog10
Copy link

@rbgirshick @ir413 ,
It might be something wrong with yaml.update. If I copy and paste the 'dict' to a new variable. yaml.safe_dump can work without above symbols, but still in a weird way, that is, the sequence of lines messed up. As a result, the generated .yaml cannot be interpreted by multiqc neither.
It looks like,

>>> yaml_str = {'top_modules': ['hicpro'], 'custom_data': {'pooled_data': {'id': 'mqc_config_file_section', 'section_name': 'Pooled data', 'description': 'This data comes from merged all Valid Pairs', 'plot_type': 'bargraph', 'pconfig': {'id': 'barplot_config_only', 'title': 'HiC-Pro: Contact Statistics After pooling', 'ylab': 'Number of pairs', 'cpswitch_counts_label': 'Number of Pairs'}, 'categories': {'cis_shortRange': {'color': '#0039e6', 'name': 'Unique: cis <= 20Kbp'}, 'cis_longRange': {'color': '#809fff', 'name': 'Unique: cis > 20Kbp'}, 'trans_interaction': {'color': '#009933', 'name': 'Unique: trans'}, 'duplicates': {'color': '#a9a2a2', 'name': 'Duplicated read pairs'}}, 'data': {'None': 0, 'dixon_3M_merged': {'cis_shortRange': 4499, 'cis_longRange': 94999, 'trans_interaction': 58939, 'duplicates': 357}, 'dixon_2M_merged': {'cis_shortRange': 4499, 'cis_longRange': 94999, 'trans_interaction': 58939, 'duplicates': 357}}}}}

>>> yaml.safe_dump(yaml_str,default_flow_style=False)
"custom_data:\n  pooled_data:\n    categories:\n      cis_longRange:\n        color: '#809fff'\n        name: 'Unique: cis > 20Kbp'\n      cis_shortRange:\n        color: '#0039e6'\n        name: 'Unique: cis <= 20Kbp'\n      duplicates:\n        color: '#a9a2a2'\n        name: Duplicated read pairs\n      trans_interaction:\n        color: '#009933'\n        name: 'Unique: trans'\n    data:\n      None: 0\n      dixon_2M_merged:\n        cis_longRange: 94999\n        cis_shortRange: 4499\n        duplicates: 357\n        trans_interaction: 58939\n      dixon_3M_merged:\n        cis_longRange: 94999\n        cis_shortRange: 4499\n        duplicates: 357\n        trans_interaction: 58939\n    description: This data comes from merged all Valid Pairs\n    id: mqc_config_file_section\n    pconfig:\n      cpswitch_counts_label: Number of Pairs\n      id: barplot_config_only\n      title: 'HiC-Pro: Contact Statistics After pooling'\n      ylab: Number of pairs\n    plot_type: bargraph\n    section_name: Pooled data\ntop_modules:\n- hicpro\n"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants