Python expected type got instead

Expected type int got float instead

The error message is the following: Solution: The issue is that PIL’s crop method takes a tuple of 4 integer values but you are passing it floats. The code: The summary: The error: Solution: Try to change your data type from to .

This error was occured. «TypeError: Expected int64, got 1e-07 of type ‘float’ instead.» . How can I do?

I have a problem. A type error was occured. But I cannot solve it. At first, I thought it was a type problem. But I noticed the problem is not simple. The reason is my poor skill. But I can’t find the solution. So, please help me.

I changed my tensorflow and keras version.

keras : 2.2.4 tensorflow : 1.13.1 
x = Dozat(21)(x) # custom Lambda layer print('x : ', x, '\n\n\n') network = Model([w, p], x) q = network.layers[8].output print(q) network.summary() network.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 
__________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== words (InputLayer) (None, 21, 2) 0 __________________________________________________________________________________________________ pos (InputLayer) (None, 21, 2) 0 __________________________________________________________________________________________________ embedding_1 (Embedding) (None, 21, 2, 128) 14541184 words[0][0] __________________________________________________________________________________________________ embedding_2 (Embedding) (None, 21, 2, 128) 9344 pos[0][0] __________________________________________________________________________________________________ reshape_1 (Reshape) (None, 21, 256) 0 embedding_1[0][0] __________________________________________________________________________________________________ reshape_2 (Reshape) (None, 21, 256) 0 embedding_2[0][0] __________________________________________________________________________________________________ concatenate_1 (Concatenate) (None, 21, 512) 0 reshape_1[0][0] reshape_2[0][0] __________________________________________________________________________________________________ bidirectional_1 (Bidirectional) (None, 21, 256) 656384 concatenate_1[0][0] __________________________________________________________________________________________________ dozat_1 (Dozat) (1, 21) 0 bidirectional_1[0][0] ================================================================================================== Total params: 15,206,912 Trainable params: 15,206,912 Non-trainable params: 0 __________________________________________________________________________________________________ 
Traceback (most recent call last): File "C:\Users\jkdsp\OneDrive\Desktop\github\git_from_the_****\Keras_parsing\keras_11_biLSTM_prac_one_example_2.py", line 105, in network.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\training.py", line 342, in compile sample_weight, mask) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\training_utils.py", line 414, in weighted score_array = fn(y_true, y_pred) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\losses.py", line 91, in binary_crossentropy return K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 3374, in binary_crossentropy _epsilon = _to_tensor(epsilon(), output.dtype.base_dtype) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 308, in _to_tensor return tf.convert_to_tensor(x, dtype=dtype) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1039, in convert_to_tensor return convert_to_tensor_v2(value, dtype, preferred_dtype, name) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1097, in convert_to_tensor_v2 as_ref=False) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1175, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 304, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 245, in constant allow_broadcast=True) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 283, in _constant_impl allow_broadcast=allow_broadcast)) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 466, in make_tensor_proto _AssertCompatible(values, dtype) File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 371, in _AssertCompatible (dtype.name, repr(mismatch), type(mismatch).__name__)) TypeError: Expected int64, got 1e-07 of type 'float' instead. 

Try to change your data type from int to float . Maybe that will solve the problem.

Читайте также:  Python read channel message

A similar discussion can be found here.

TypeError: Expected String, got 0 of type int instead, Error: Argument must be a dense tensor: range(2, 3) — got shape [1], but wanted [] 0 Getting «PermissionDeniedError» when running the …

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

PyCharm warning: Expected type ‘ObjectType’, got ‘Type[Query]’ instead #1100

PyCharm warning: Expected type ‘ObjectType’, got ‘Type[Query]’ instead #1100

Comments

class Query(graphene.ObjectType): # . schema = Schema(query=Query)

image

Related to #814 which was automatically closed due to staleness.

The text was updated successfully, but these errors were encountered:

@KingDarBoja I use PyCharm 2019.2.4 Professional Edition

I can confirm such behaviour on my PyCharm too;

Warning Query Type PyCharm GraphQL

PyCharm 2019.2.5 (Community Edition) Build #PC-192.7142.56, built on November 19, 2019 Runtime version: 11.0.4+10-b304.77 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 GC: ParNew, ConcurrentMarkSweep Memory: 976M Cores: 4 Registry: Non-Bundled Plugins: org.intellij.plugins.markdown, Docker 

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Don’t automatically close this please

@denizdogan Looks like the issue got solved but will be released on Graphene v3-alpha versions instead of v2, just saying, the final word is under Graphql-Python Team 😄

Читайте также:  Ubuntu установить python определенной версии

Still present on 2020.1, any news?

I can confirm that this is still present in 2020.1 professional. It would be helpful it it gets solved.

Came across this looking for the same PyCharm warning, but in a different situation. I’m not a user of this repo, so I won’t take the time to locate the code and PR the simple fix for it.

Whenever you see PyCharm complain with

Expected type X, got Type[X] instead 

that’s a possible type hinting misunderstanding. See this for more information.

# Wrong class Schema: def __init__(self, query: MyClass): # Right from typing import Type class Schema: def __init__(self, query: Type[MyClass]):

Thanks for the hint. I changed the type specification and PyCharm does not anymore complain about a type mismatch. Thanks formigone.

@AndHam89 Where did you change the type specification? In the source of graphene? It’s still complaining for me

@tobiasfeil You need to change your type specification in you Python code as formigone pointed out. If you refer to the type of a class you need to use the syntax Type[MyClass] if you have a parameter which is of type MyClass.

image

Thank you for the reply! I’m sorry I still don’t understand how to do this, since I’m not defining the class Schema in my own code. All I’m doing is using graphene.Schema :

So I don’t know where the type hint should go, since there’s no class Schema in my code. Would you be so kind to tell me how you accomplished this? Did you subclass graphene.Schema ? Thanks in advance 🙂

image

Thank you for the reply! I’m sorry I still don’t understand how to do this, since I’m not defining the class Schema in my own code. All I’m doing is using graphene.Schema :

So I don’t know where the type hint should go, since there’s no class Schema in my code. Would you be so kind to tell me how you accomplished this? Did you subclass graphene.Schema ? Thanks in advance 🙂

change the doc present in graphene/types/schema.py

query (ObjectType): Root query ObjectType. Describes entry point for fields to read
data in your Schema.

query (Type[ObjectType]): Root query ObjectType. Describes entry point for fields to read
data in your Schema.

After that problem will resolve

image

Thank you for the reply! I’m sorry I still don’t understand how to do this, since I’m not defining the class Schema in my own code. All I’m doing is using graphene.Schema :

So I don’t know where the type hint should go, since there’s no class Schema in my code. Would you be so kind to tell me how you accomplished this? Did you subclass graphene.Schema ? Thanks in advance 🙂

change the doc present in graphene/types/schema.py

Читайте также:  Java событие при наведении мыши

query (ObjectType): Root query ObjectType. Describes entry point for fields to read data in your Schema.

query (Type[ObjectType]): Root query ObjectType. Describes entry point for fields to read data in your Schema.

After that problem will resolve

To be concrete, it’s weird that pycharm will take the comment as a source for typing checking

Источник

Python expected type got instead

I’m mainly a Java dev and learning Python so maybe it’s just my misunderstanding. The following code in Pycharm:

class Duck: def quack(self): «»»Quack»»» class FakeDuck: def quack(self): «»»Quack quack»»» class Farm: def __init__(self, duck: Duck): duck.quack() f1 = Farm(Duck()) f2 = Farm(FakeDuck()) #

will display warning: Expected type ‘Duck’, got ‘FakeDuck’ instead at the last line. I read that duck typing is a pretty well established principle in writing Python applications. I’d like to use type annotation for better code completion and for documenting of expected types, but not to limit clients of this API to use only the expected type. Doesn’t the word (type) hint imply that this is just a recommend type, but not mandatory. What can be the solution for my use case? I’d like to use type annotation but also support duck typing. I could think only about Union[Duck, Any], but it looks ugly.

  1. Pycharm does only what the spec mandate. There is a lot of talks about type checkers in the type hint spec. Also seen many opinions in discussions that the type hints are against duck typing. The solution might be: PEP 544
  2. The spec is ambiguous about warnings. Pycharm may implement «smarter» checks later.

The only solution I found to convey the message: «Expected this type but feel free to use duck typing» is either using Union[Type, Any] or use some custom docstring convention. Even using :type in docstring generates the warning.

Источник

Оцените статью