Skip to content

Commit f65dd24

Browse files
author
y-p
committed
CLN: create mode.use_inf_as_null, mode.sim_interactive options
1 parent 3c6961d commit f65dd24

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

pandas/core/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def isnull_old(obj):
9494
else:
9595
return obj is None
9696

97-
def use_inf_as_null(flag):
98-
'''
97+
def _use_inf_as_null(key):
98+
'''Option change callback for null/inf behaviour
9999
Choose which replacement for numpy.isnan / -numpy.isfinite is used.
100100
101101
Parameters
@@ -113,6 +113,7 @@ def use_inf_as_null(flag):
113113
* http://stackoverflow.com/questions/4859217/
114114
programmatically-creating-variables-in-python/4859312#4859312
115115
'''
116+
flag = get_option(key)
116117
if flag == True:
117118
globals()['isnull'] = isnull_old
118119
else:
@@ -1179,7 +1180,7 @@ def in_interactive_session():
11791180
returns True if running under python/ipython interactive shell
11801181
"""
11811182
import __main__ as main
1182-
return not hasattr(main, '__file__') or get_option('test.interactive')
1183+
return not hasattr(main, '__file__') or get_option('mode.sim_interactive')
11831184

11841185
def in_qtconsole():
11851186
"""

pandas/core/config_init.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,27 @@
139139
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
140140
cf.register_option('line_width', 80, pc_line_width_doc)
141141

142-
tc_interactive_doc="""
142+
tc_sim_interactive_doc="""
143143
: boolean
144144
Default False
145145
Whether to simulate interactive mode for purposes of testing
146146
"""
147-
with cf.config_prefix('test'):
148-
cf.register_option('interactive', False, tc_interactive_doc)
147+
with cf.config_prefix('mode'):
148+
cf.register_option('sim_interactive', False, tc_sim_interactive_doc)
149+
150+
use_inf_as_null_doc="""
151+
: boolean
152+
True means treat None, NaN, INF, -INF as null (old way),
153+
False means None and NaN are null, but INF, -INF are not null
154+
(new way).
155+
"""
156+
157+
# we don't want to start importing evrything at the global context level
158+
# or we'll hit circular deps.
159+
def use_inf_as_null_cb(key):
160+
from pandas.core.common import _use_inf_as_null
161+
_use_inf_as_null(key)
162+
163+
with cf.config_prefix('mode'):
164+
cf.register_option('use_inf_as_null', False, use_inf_as_null_doc,
165+
cb=use_inf_as_null_cb)

pandas/tests/test_common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import unittest
66

77
from pandas import Series, DataFrame, date_range, DatetimeIndex
8-
from pandas.core.common import notnull, isnull, use_inf_as_null
8+
from pandas.core.common import notnull, isnull
99
import pandas.core.common as com
1010
import pandas.util.testing as tm
11+
import pandas.core.config as cf
1112

1213
import numpy as np
1314

@@ -29,15 +30,15 @@ def test_notnull():
2930
assert not notnull(None)
3031
assert not notnull(np.NaN)
3132

32-
use_inf_as_null(False)
33+
cf.set_option("mode.use_inf_as_null",False)
3334
assert notnull(np.inf)
3435
assert notnull(-np.inf)
3536

36-
use_inf_as_null(True)
37+
cf.set_option("mode.use_inf_as_null",True)
3738
assert not notnull(np.inf)
3839
assert not notnull(-np.inf)
3940

40-
use_inf_as_null(False)
41+
cf.set_option("mode.use_inf_as_null",False)
4142

4243
float_series = Series(np.random.randn(5))
4344
obj_series = Series(np.random.randn(5), dtype=object)

pandas/tests/test_format.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def test_repr_should_return_str (self):
112112
self.assertTrue(type(df.__repr__() == str)) # both py2 / 3
113113

114114
def test_repr_no_backslash(self):
115-
pd.set_option('test.interactive', True)
115+
pd.set_option('mode.sim_interactive', True)
116116
df = DataFrame(np.random.randn(10, 4))
117117

118118
self.assertTrue('\\' not in repr(df))
119-
pd.reset_option('test.interactive')
119+
pd.reset_option('mode.sim_interactive')
120120

121121
def test_to_string_repr_unicode(self):
122122
buf = StringIO()
@@ -409,7 +409,7 @@ def test_frame_info_encoding(self):
409409
fmt.set_printoptions(max_rows=200)
410410

411411
def test_wide_repr(self):
412-
set_option('test.interactive', True)
412+
set_option('mode.sim_interactive', True)
413413
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
414414
df = DataFrame([col(20, 25) for _ in range(10)])
415415
set_option('print.expand_frame_repr', False)
@@ -423,11 +423,11 @@ def test_wide_repr(self):
423423
self.assert_(len(wider_repr) < len(wide_repr))
424424

425425
reset_option('print.expand_frame_repr')
426-
set_option('test.interactive', False)
426+
set_option('mode.sim_interactive', False)
427427
set_option('print.line_width', 80)
428428

429429
def test_wide_repr_named(self):
430-
set_option('test.interactive', True)
430+
set_option('mode.sim_interactive', True)
431431
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
432432
df = DataFrame([col(20, 25) for _ in range(10)])
433433
df.index.name = 'DataFrame Index'
@@ -446,11 +446,11 @@ def test_wide_repr_named(self):
446446
self.assert_('DataFrame Index' in line)
447447

448448
reset_option('print.expand_frame_repr')
449-
set_option('test.interactive', False)
449+
set_option('mode.sim_interactive', False)
450450
set_option('print.line_width', 80)
451451

452452
def test_wide_repr_multiindex(self):
453-
set_option('test.interactive', True)
453+
set_option('mode.sim_interactive', True)
454454
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
455455
midx = pandas.MultiIndex.from_arrays([np.array(col(10, 5)),
456456
np.array(col(10, 5))])
@@ -471,11 +471,11 @@ def test_wide_repr_multiindex(self):
471471
self.assert_('Level 0 Level 1' in line)
472472

473473
reset_option('print.expand_frame_repr')
474-
set_option('test.interactive', False)
474+
set_option('mode.sim_interactive', False)
475475
set_option('print.line_width', 80)
476476

477477
def test_wide_repr_multiindex_cols(self):
478-
set_option('test.interactive', True)
478+
set_option('mode.sim_interactive', True)
479479
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
480480
midx = pandas.MultiIndex.from_arrays([np.array(col(10, 5)),
481481
np.array(col(10, 5))])
@@ -497,11 +497,11 @@ def test_wide_repr_multiindex_cols(self):
497497
self.assert_(len(wide_repr.splitlines()) == 14 * 10 - 1)
498498

499499
reset_option('print.expand_frame_repr')
500-
set_option('test.interactive', False)
500+
set_option('mode.sim_interactive', False)
501501
set_option('print.line_width', 80)
502502

503503
def test_wide_repr_unicode(self):
504-
set_option('test.interactive', True)
504+
set_option('mode.sim_interactive', True)
505505
col = lambda l, k: [tm.randu(k) for _ in xrange(l)]
506506
df = DataFrame([col(20, 25) for _ in range(10)])
507507
set_option('print.expand_frame_repr', False)
@@ -515,18 +515,18 @@ def test_wide_repr_unicode(self):
515515
self.assert_(len(wider_repr) < len(wide_repr))
516516

517517
reset_option('print.expand_frame_repr')
518-
set_option('test.interactive', False)
518+
set_option('mode.sim_interactive', False)
519519
set_option('print.line_width', 80)
520520

521521
def test_wide_repr_wide_long_columns(self):
522-
set_option('test.interactive', True)
522+
set_option('mode.sim_interactive', True)
523523

524524
df = DataFrame({'a': ['a'*30, 'b'*30], 'b': ['c'*70, 'd'*80]})
525525

526526
result = repr(df)
527527
self.assertTrue('ccccc' in result)
528528
self.assertTrue('ddddd' in result)
529-
set_option('test.interactive', False)
529+
set_option('mode.sim_interactive', False)
530530

531531
def test_to_string(self):
532532
from pandas import read_table

0 commit comments

Comments
 (0)