File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1
1
import sys
2
2
from typing import List
3
3
4
+ import pytest
5
+
4
6
import pandas as pd
5
7
from pandas import api , compat
6
8
import pandas ._testing as tm
@@ -311,3 +313,16 @@ def test_util_testing_deprecated_direct(self):
311
313
312
314
assert "pandas.util.testing is deprecated" in str (m [0 ].message )
313
315
assert "pandas.testing instead" in str (m [0 ].message )
316
+
317
+ def test_util_in_top_level (self ):
318
+ # in a subprocess to avoid import caching issues
319
+ import subprocess
320
+
321
+ out = subprocess .check_output (
322
+ ["python" , "-c" , "import pandas; pandas.util.testing" ],
323
+ stderr = subprocess .STDOUT ,
324
+ ).decode ()
325
+ assert "pandas.util.testing is deprecated" in out
326
+
327
+ with pytest .raises (AttributeError , match = "foo" ):
328
+ pd .util .foo
Original file line number Diff line number Diff line change 1
1
from pandas .util ._decorators import Appender , Substitution , cache_readonly # noqa
2
2
3
+ from pandas import compat
3
4
from pandas .core .util .hashing import hash_array , hash_pandas_object # noqa
5
+
6
+ # compatibility for import pandas; pandas.util.testing
7
+
8
+ if compat .PY37 :
9
+
10
+ def __getattr__ (name ):
11
+ if name == "testing" :
12
+ import pandas .util .testing # noqa: F401
13
+ else :
14
+ raise AttributeError (f"module 'pandas.util' has no attribute '{ name } '" )
15
+
16
+
17
+ else :
18
+
19
+ class _testing :
20
+ def __getattr__ (self , item ):
21
+ import pandas .util .testing
22
+
23
+ return getattr (pandas .util .testing , item )
24
+
25
+ testing = _testing ()
26
+
27
+
28
+ del compat
You can’t perform that action at this time.
0 commit comments