Questions tagged [python-datamodel]

For questions about various details related to Python data model: built-in types, classes, metaclasses, magic __dunder__ methods, operators, object initialization, attribute lookup, etc. Always remember to use 'python' tag together with this one. Using specific tag like 'operators' or 'metaclass' when appropriate is encouraged.

99 questions
0
votes
0 answers

Should I use Model objects from library or make it myself?

I'm working with gitlab webhooks and I need to choose which data model to use in my project. I'm using the Python-gitlab library to work with gitlab, and this library has its own data models for all objects that use gitlab, for example, a merge…
0
votes
0 answers

How to avoid clashes between ORM model name and service layer data model?

I am using Peewee as ORM provider and my BaseModel subclasses correspond to normalized database tables. These names will be part of my data access layer (DAL) API. Then we will want to define the higher level data model which will have probably…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
0
votes
1 answer

Are there any unique features provided only by metaclasses in Python?

I have read answers for this question: What are metaclasses in Python? and this question: In Python, when should I use a meta class? and skimmed through documentation: Data model. It is very possible I missed something, and I would like to clarify:…
alex_why
  • 95
  • 3
0
votes
1 answer

Usage of __setattr__ to rewrite whole method of library class issue: missing 1 required positional argument: 'self'

I've got some imported packages with tricky structure and need to call some method that bases on lots of other methods with non-default parameters, which are not class attributes themself like pipeline in sklearn. Minimal example of this module…
MosQuan
  • 85
  • 1
  • 11
0
votes
1 answer

What to input for testing a completed Data Model (Python)?

I am a data science beginner, and I now have built a Python data model. In the data cleaning part, I had to drop some columns, add new columns, hash some columns into new columns, change some columns to numeric For example (not from any real…
J R
  • 436
  • 3
  • 7
0
votes
0 answers

id( ) function returns different value when using same float number

When declared an integer to a variable, both the integer and variable returns the same id value. But, in case of float, it returns a different id value. What is the reason behind it? As below, a=10 >>> id(a) 48068132 >>> id(10) 48068132 >>>…
0
votes
1 answer

How to model POST body in a clean architecture

I'm asking myself a question about clean architecture. Let's imagine a small api that allow us to create and get a user using that type of archi. This app has two endpoints and store the data in a database. Let's say that we have a db model that…
0
votes
1 answer

imported variable update is not reflecting in the parent module

i have two modules, main and update. in main, i declare a dictionary of references and a list for each value. In update i update the age, but i do not see the update reflecting in the main module again. main module candidates = {'goutham': {'Age':…
K G
  • 27
  • 8
0
votes
2 answers

Usage of python function comparison dunders

Question Python functions have comparison dunders (see print out below). But they are NotImplemented. Fair enough. But what is their intended use, and how does one go about using them? When I assign a callable to func.__gt__, I'm not seeing it be…
thorwhalen
  • 1,920
  • 14
  • 26
0
votes
1 answer

How to do ETL on millon rows of data using python?

I've a pgAdmin database which contains millions of rows in geojson format.Using this table I create Tableau dashboard. Since the rows contain data in geojson format I've to query like this: select jsondata ->> 'id' as id, jsondata -> 'properties'…
0
votes
0 answers

Custom binary operations and getattr

I would like to implement a class with custom binary operators, such that class One: def __lt__(self,other): return 1 < other Python seems to be able to automatically create the reverse operation for the operators >, >=, <, <=, however,…
John Titor
  • 461
  • 3
  • 13
0
votes
1 answer

When the Python __call__ method gets extra first argument?

The following sample import types import pprint class A: def __call__(self, *args): pprint.pprint('[A.__call__] self=%r, args=%r' % (self, list(args))) class B: pass if __name__ == '__main__': a = A() …
0
votes
2 answers

From a python dictionary how do I save the key and value to a *.txt file

How do I print the key and value to a *.txt file from a dictionary? I have tried to read the data and to print it to a *.txt file but the name.txt file is empty. #The code that I have tried #my_dict is given above def create_dict(): with…
Ethan
  • 77
  • 1
  • 9
0
votes
2 answers

How to implement the __getitem__ dunder method in python to get attribute values?

I have the following code: class Personne: def __init__(self, name, age): self.name = name self.age = age def __getitem__(self, *args): keys = list(*args) return [self.__dict__[key] for key in keys] if…
moctarjallo
  • 1,479
  • 1
  • 16
  • 33
0
votes
1 answer

Python datastructure for storage, computing and mapping

My data will likely be in this format: 1-universal Type_A=10, Type_B=20, Type_C=30 Local set 1: Type_D=40, Type_C =30, Type_B=10, Type_A=15, Type_E=45 (ie A,B,C,D,E may not be in order) Local set 2: Type_C =40, Type_B=5 4,5,6….and so on will…