Comments (11)
Just ran into this problem too – my frozen test code was importing Pandas, and Pandas import failed with
TypeError: type 'pandas.tslib._Timestamp' is not dynamically allocated but its base type 'FakeDatetime' is dynamically allocated
I got it to work by explicitly importing Pandas before the test code runs.
from freezegun.
Why this issue is closed? It's still a problem.
Could you please reopen @spulec ?
from freezegun.
To give a concrete example of this suggestion from @ze-phyr-us:
I got it to work by explicitly importing Pandas before the test code runs.
I was able to do this by adding import pandas
to my global conftest.py
.
from freezegun.
I'm going to close this. Please reopen if you confirm it is still an issue
from freezegun.
FYI, this still seems to be an issue, even using the latest versions of Pandas and freezegun:
@freeze_time("2020-01-01")
def test_freeze_time_pandas():
import pandas
Python 2:
___________________________ test_freeze_time_pandas ____________________________
test_model_factory.py:89: in test_freeze_time_pandas
import pandas
../../../../../venv/lib/python2.7/site-packages/pandas/__init__.py:25: in <module>
from pandas import hashtable, tslib, lib
pandas/tslib.pyx:918: in init pandas.tslib (pandas/tslib.c:119031)
???
pandas/tslib.pyx:805: in pandas.tslib.NaTType.__new__ (pandas/tslib.c:16573)
???
E TypeError: __new__() takes exactly one argument (4 given)
Python 3:
___________________________ test_freeze_time_pandas ____________________________
test_model_factory.py:89: in test_freeze_time_pandas
import pandas
../../../.tox/py36/lib/python3.6/site-packages/pandas/__init__.py:25: in <module>
from pandas import hashtable, tslib, lib
pandas/tslib.pyx:1051: in init pandas.tslib (pandas/tslib.c:116027)
???
E TypeError: type 'pandas.tslib._Timestamp' is not dynamically allocated but its base type 'FakeDatetime' is dynamically allocated
This is admittedly a contrived example, and in my case it seems like I can avoid this by using freeze_time
as a context manager, or reworking the complex import chain. However, I can imagine a situation where one or both of those things might not be possible/practical.
from freezegun.
Which version of freezegun are you on? We've had this issue in the past, but I thought it was fixed with #13
from freezegun.
Installed current pip version today
On 26 Jun 2015 19:30, "Steve Pulec" [email protected] wrote:
Which version of freezegun are you on? We've had this issue in the past,
but I thought it was fixed with #13
#13—
Reply to this email directly or view it on GitHub
#98 (comment).
from freezegun.
Ah, I have read the other issue and I see it is the same symptom but a different case
It was fixed in #13 for the case of import freezegun
kills non-frozen tests which import Pandas
My case is a frozen test that contains code that imports Pandas
Is there any insight into why Pandas spits the dummy? Is it something that could be solved?
I'm currently using python-libfaketime
instead
from freezegun.
I think Pandas does some C-level manipulation or use of the datetime/time modules. I've dug into it a bit, but not found a way that we could work around it.
from freezegun.
Apparently the issue can be fixed using workaround by importing pandas
somewhere before the test, like in conftest
. But anyway it looks like a workaround (especially if you need to add some ignore linters - unused import etc). I hope that some time in future we would be able to figure out the problem and fix it...
from freezegun.
Importing pandas early is not always a good idea, since it consumes a lot of memory without actually doing anything. If you have a project that can be invoked in many different ways (think of one code base that can run both as a webserver and as a task queue processor in Docker containers) then you want to avoid that pandas import if you're never going to need it. You don't always have the option of splitting the code base.
My workaround is to have a conditional early import when running tests.
from freezegun.
Related Issues (20)
- Maintenance plans HOT 3
- 1.3.0: `freezegun/__init__.py` is missing new version number HOT 1
- [Discussion] about freezing asyncio HOT 7
- ``PermissionError: [Errno 1] Operation not permitted`` appears when upgrading to ``1.3.0`` HOT 7
- Freezegun doesn't mock pointers to date functions HOT 1
- Tag for 1.2.2 is missing HOT 1
- Python 3.12: Deprecation warnings related to datetime.datetime.utcfromtimestamp HOT 2
- Time is not freezed when using `uvloop` event loop
- unsupported operand type(s) for +: 'FakeDatetime' and 'FakeDatetime'
- Datetime and Time packages do not have the same behavior when being frozen HOT 4
- timezone free datetime.datetime.fromtimestamp returns original datetime.datetime HOT 1
- Adding a return value to tick()
- Could have some problem with Django with TIME_ZONE setting
- Test regressions on Python 3.13.0b1 HOT 2
- `FakeDatetime`'s `timestamp()` is not consistent with `datetime().timestamp()` HOT 1
- consider overriding == on FakeDatetimeMeta HOT 2
- Freeze time doesn't work with FastAPI + pydantic V2 HOT 1
- [Bug] `tz_offset` shifts `datetime` which is instantiated with `tz` argument
- Possible to patch user-defined functions?
- FG incorrectly causes monotonic time to go back
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 freezegun.