GithubHelp home page GithubHelp logo

Comments (4)

lk-geimfari avatar lk-geimfari commented on May 25, 2024

I'm not sure aliases make sense for custom fields, since you can already give them any name you want.

from mimesis.

lk-geimfari avatar lk-geimfari commented on May 25, 2024

Well, almost any. Most names allowed for aliases aren't allowed for custom fields (like emojis and stuff).

from mimesis.

mheguy-flo avatar mheguy-flo commented on May 25, 2024

That makes sense if everything is done statically in code.
In my case, things are not static. Here's an example of how I'm using your project:

fieldset = Fieldset()
# file represents an external data source
aliases = json.load(file)
# aliases = { "col 1": "positive_number_under_10"}
fieldset.aliases.update(aliases)
fieldset.register_handlers(
    (
        ("positive_number_under_10", positive_number_under_10),
    )
)
data: dict[str, list[Any]] = {}

# columns comes from a database schema
for col in columns:
    data[col.name] = fieldset(col.name, i=rows_in_table)

Neither the aliases nor the columns are determined before runtime.
I cannot register the handlers with the column names as they are generally not valid python identifiers.

My (ugly) workaround currently is to make aliases global and use it in the lookup.
But this seems like a needless workaround since it's just duplicating the aliases feature built into mimesis.

You can see in #1515, you can support aliases and custom handlers by moving a single line of code from _lookup_method to perform.

from mimesis.

lk-geimfari avatar lk-geimfari commented on May 25, 2024

I see. I'll merge your PR and release new version later this weekend. Thank you!

from mimesis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.