google / google/ml_collections

ConfigDict does not allow dictionary key to be int type

Open
#13 0 comments 0 reactions 1 assignee Claimed by @mohitreddy1996 View on GitHub
bug
Dominant language
Python
Stars
1k
Forks
49
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

ConfigDict() does not allow dictionary with int data type as key

**To Reproduce**

from ml_collections import ConfigDict

tmp = ConfigDict()
tmp.demo0 = 10 # no bug
tmp.demo1 = '10' # no bug
tmp.demo2 = {'0': '10', '1': '20'} # no bug
tmp.demo3 = {0: '10', 1: '20'} # bug

***ConfigDict***

![image](https://user-images.githubusercontent.com/49025029/154760025-35982702-41c2-4909-80b6-6260af73919a.png)

***ConfigFlags***

im not sure how to provide config flags, therefore i created a brand new conda virtual env to demonstrate the bug.

~$ conda create --name bug python=3.8
~$ conda activate bug
~$ pip install ml-collections
~$ python

from ml_collections import ConfigDict
tmp = ConfigDict()
tmp.demo = {0: '10', 1: '20'}

**Expected behavior**

the should run, and save the dictionary without issue

**Environment:**
- OS: ubuntu
- OS Version: 20
- Python: 3.8

**Additional context**

when I changed the key to str type, the code runs. However I want to be able to use str type.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.