types

Why is VS Code unable to convert this List into a Int?

Why is VS Code unable to convert this List into a Int? Question: def load_matrix(): matrix = sys.stdin.read() matrix = matrix.strip().split(‘n’) matrix = [row.split(‘ ‘) for row in matrix] for m in matrix: matrix=[int(l) for l in m] print("n Data Loaded Sucessfully") print("n") var=pd.DataFrame(matrix) return var Look at this piece of code. I am trying …

Total answers: 1

How to change column datatype when loading csv in postgresql

How to change column datatype when loading csv in postgresql Question: I have a big script, the result is that the data is stored in a dataframe and then in csv. Then csv is opened and written to PostgreSQL. But there is a problem that the data type of one column is int4, and after …

Total answers: 2

Is there a difference between torch.IntTensor and torch.Tensor

Is there a difference between torch.IntTensor and torch.Tensor Question: When using PyTorch tensors, is there a point to initialize my data like so: X_tensor: torch.IntTensor = torch.IntTensor(X) Y_tensor: torch.IntTensor = torch.IntTensor(Y) Or should I just do the ‘standard’: X_tensor: torch.Tensor = torch.Tensor(X) Y_tensor: torch.Tensor = torch.Tensor(Y) even though I know X: list[list[int] and Y: list[list[int] …

Total answers: 2

Getting the generic arguments of a subclass

Getting the generic arguments of a subclass Question: I have a generic base class and I want to be able to inspect the provided type for it. My approach was using typing.get_args which works like so: from typing import Generic, Tuple, TypeVarTuple, get_args T = TypeVarTuple("T") class Base(Generic[*T]): values: Tuple[*T] Example = Base[int, str] print(get_args(Example)) …

Total answers: 2

How would I implement my own container with type hinting?

How would I implement my own container with type hinting? Question: Say I want to make a container class MyContainer and I want to enable its use in type hints like def func(container: MyContainer[SomeType]), in a similar way to how I would be able to do def func(ls: list[SomeType]). How would I do that? Asked …

Total answers: 2

how can I use builtin function in my python divisor code?

how can I use builtin function in my python divisor code? Question: I’m getting error on the line with (if counter > max_count:). It says not supported between instances of ‘int’ and ‘builtin_function_or_method’. I can’t underestand what is the problem! def divisors(num): counter=1 for i in range(1,num): x = num%i if x==0: counter+=1 return counter …

Total answers: 1

Comparing parquet file schema to db schema in python (including decimal precisions)

Comparing parquet file schema to db schema in python (including decimal precisions) Question: If I have a parquet file with columns that have, for example, types Decimal(38, 22) or Decimal(20, 4), is there a way to compare them to the existing schema in database in python (for example check if Decimal(38, 22) corresponds to the …

Total answers: 1

Python annotate type as regex pattern

Python annotate type as regex pattern Question: I have a dictionary annotation class OrderDict(TypedDict): name: str price: float time: str The value of time: will always be formatted like 2022-01-01 00:00:00, or "%Y-%m-%d %H:%M:%S". I’d like a way to express this in the type annotation Something like class OrderDict(TypedDict): name: str price: float time: Pattern["%Y-%m-%d …

Total answers: 2

Expressing semantic content of tuple values in type annotations

Expressing semantic content of tuple values in type annotations Question: I’m modeling a financial exchange class Exchange(ABC): @abstractproperty def balances(self) -> Dict[str, Tuple[float, float]]: … The semantic content of .balances return type is a dict that is {asset: (quantity, proportion), …} e.g. {"BTC": (0.0015, .30), "ETH": (0.10, .20), "LTC": (5, .50)} The problem is that …

Total answers: 1

Has anyone used Polars and Seaborn or Matplotlib together?

Has anyone used Polars and Seaborn or Matplotlib together? Question: Has anyone used a Polars dataframe with Seaborn to graph something? I’ve been working through a notebook on Kaggle that used Pandas, and I wanted to refactor it to Polars. The dataframe I’m working with looks like this: PassengerID (i64) Survived (i64) Pclass (i64) Name …

Total answers: 1