Coder Social home page Coder Social logo

Comments (11)

vitawasalreadytaken avatar vitawasalreadytaken commented on July 17, 2024 19

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.

marcinmilewski1 avatar marcinmilewski1 commented on July 17, 2024 16

Why this issue is closed? It's still a problem.

Could you please reopen @spulec ?

from freezegun.

bhrutledge avatar bhrutledge commented on July 17, 2024 14

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.

spulec avatar spulec commented on July 17, 2024 10

I'm going to close this. Please reopen if you confirm it is still an issue

from freezegun.

bhrutledge avatar bhrutledge commented on July 17, 2024 7

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.

spulec avatar spulec commented on July 17, 2024

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.

anentropic avatar anentropic commented on July 17, 2024

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.

anentropic avatar anentropic commented on July 17, 2024

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.

spulec avatar spulec commented on July 17, 2024

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.

sshishov avatar sshishov commented on July 17, 2024

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.

hedleyroos avatar hedleyroos commented on July 17, 2024

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)

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.