Comments (6)
Hi! Actually, there is an accumulator
argument for such cases: https://mimesis.name/en/master/api.html#mimesis.Numeric.increment
Here is a usage example:
>>> numeric.increment()
1
>>> numeric.increment(accumulator="a")
1
>>> numeric.increment()
2
numeric.increment(accumulator="a")
2
>>> numeric.increment(accumulator="b")
1
>>> numeric.increment(accumulator="a")
3
from mimesis.
In your case, you are using schemas wrong way.
Instead of doing this:
for i in range(0,5):
data = schema.create(5)
print(data[0]['id'])
Do this:
for i in schema.create(5):
print(i['id'])
from mimesis.
In your case, you are using schemas wrong way.
In my code example, I'm trying to create 5 fullfilled schemas (that I could then export 5 times) based on the same logical schema. And here, I cannot use a new accumulator every time, unless I instantiate a new Schema
object every time.
from mimesis.
@rgoubet Sorry, I don't get the idea. Can you, please, illustrate it on example?
from mimesis.
My use case is that I want to create multiple, large random data sets in Excel files (generated with openpxl) for stress test purposes. So, let's say I want to create 5 files with 1 million rows each (I use 4 columns for readability, while in practice I get 30):
from mimesis import Field, Schema
from openpyxl import Workbook
_ = Field()
schema = Schema(schema=lambda: {
"id": _('increment'),
"timestamp": _('datetime'),
'version': _('version'),
'e-mail': _('person.email', domains=['argenx.com']),
'token': _('token_hex'),
}
Now, I'll run a loop for each file, and use the iterator
to preserve memory:
for i in range(0,5):
wb = Workbook(write_only=True)
ws = wb.create_sheet()
for ix, v in enumerate(schema.iterator(1_000_000)):
if ix==0:
ws.append(list(v.keys())) # write headers
else:
ws.append(list(v.values())) # write data
xl_file = os.path.join(path, f'data{str(i).zfill(3)}.xlsx')
wb.save(xl_file)
wb.close()
Now, it's all good, except that the id
column increment continues in each file instead of restarting from 1. In my case, that could have been an issue as it can then become a larger number than I would want for the data type I want (turned out ok in the end).
As I said, maybe I missed something, but it would be nice to have a reset option (e.g. in the create
and iterator
methods) for the increments. Not critical at all, though.
from mimesis.
This issue has been automatically marked as stale because it has not had activity. It will be closed if no further activity occurs. Thank you for your contributions.
from mimesis.
Related Issues (20)
- Add please connected data support HOT 5
- Add croatian locale HOT 5
- Person date of birth HOT 5
- generic.pyi has incorrect attribute for providers.Cryptographic HOT 1
- Support for secondary addresses
- [Integration] Pytest plugin is outdated HOT 4
- Suppor Fieldset fixture for pytest plugin.
- Codecov reporting wrong coverage information. HOT 8
- factory_boy integration out of the box. HOT 1
- Support python < 3.10 HOT 1
- Remove inappropriate words from your random text selections HOT 3
- A custom handler with an alias returns an error when using the alias HOT 4
- Tests that write to files fail in windows
- Duplicate/overwritten test
- 15.1.0: pytest fails onscanning units HOT 5
- Use Markdown for Readme
- Mimesis fails on FreeBSD HOT 1
- Location aware test data HOT 2
- Cannot import Person from partially initialized module. HOT 2
- Add support of GPT provider. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mimesis.