Skip to content

Commit

Permalink
shortened lines to pass linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dickreuter committed Dec 13, 2016
1 parent 2028924 commit 3c94206
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 0 additions & 2 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ users upgrade to this version.

Highlights include:

- Building pandas for development now requires ``cython >= 0.23`` (:issue:`14831`)

Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations <whatsnew_0200.deprecations>` before updating.

Expand Down Expand Up @@ -61,7 +60,6 @@ Other enhancements
- The ``usecols`` argument in ``pd.read_csv`` now accepts a callable function as a value (:issue:`14154`)
- ``pd.DataFrame.plot`` now prints a title above each subplot if ``suplots=True`` and ``title`` is a list of strings (:issue:`14753`)
- ``pd.Series.interpolate`` now supports timedelta as an index type with ``method='time'`` (:issue:`6424`)
- ``pandas.io.json.json_normalize`` If meta keys are not always present a new option to set errors="ignore" (:issue:`14583`)
- ``pandas.io.json.json_normalize`` gained the option ``errors='ignore'|raise``; the default is raise and is backward compatible. (:issue:`14583`)


Expand Down
11 changes: 8 additions & 3 deletions pandas/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,12 @@ def json_normalize(data, record_path=None, meta=None,
path to records is ['foo', 'bar']
meta_prefix : string, default None
error: {'raise', 'ignore'}, default 'raise'
* ignore: will ignore KeyError if keys listed in meta are not always present
* raise: will raise KeyError if keys listed in meta are not always present
* ignore: will ignore KeyError if keys listed in meta are not
always present
* raise: will raise KeyError if keys listed in meta are not
always present
.. versionadded:: 0.20.0
Returns
-------
Expand Down Expand Up @@ -850,7 +854,8 @@ def _recursive_extract(data, path, seen_meta, level=0):
if errors == 'ignore':
meta_val = np.nan
else:
raise KeyError("Try running with errors='ignore' as key %s is not always present.", e)
raise KeyError("Try running with errors='ignore'"
"as key %s is not always present.", e)
meta_vals[key].append(meta_val)

records.extend(recs)
Expand Down
15 changes: 6 additions & 9 deletions pandas/io/tests/json/test_json_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def test_nested_flattens(self):


def test_json_normalize_errors(self):
# GH14583: If meta keys are not always present a new option to set errors='ignore' has been implemented
# GH14583: If meta keys are not always present
# a new option to set errors='ignore' has been implemented
i = {
"Trades": [{
"general": {
Expand All @@ -238,38 +239,33 @@ def test_json_normalize_errors(self):
"symbol": "AAPL",
"name": "Apple",
"price": "0"

}, {

"symbol": "GOOG",
"name": "Google",
"price": "0"

}
]
}
}, {
"general": {
"tradeid": 100,
"stocks": [{

"symbol": "AAPL",
"name": "Apple",
"price": "0"

}, {
"symbol": "GOOG",
"name": "Google",
"price": "0"

}
]
}
}
]
}
j = json_normalize(data=i['Trades'], record_path=[['general', 'stocks']],
meta=[['general', 'tradeid'], ['general', 'trade_version']], errors='ignore')
meta=[['general', 'tradeid'], ['general', 'trade_version']],
errors='ignore')
expected={'general.trade_version': {0: 1.0, 1: 1.0, 2: '', 3: ''},
'general.tradeid': {0: 100, 1: 100, 2: 100, 3: 100},
'name': {0: 'Apple', 1: 'Google', 2: 'Apple', 3: 'Google'},
Expand All @@ -280,7 +276,8 @@ def test_json_normalize_errors(self):

self.assertRaises(KeyError,
json_normalize, data=i['Trades'], record_path=[['general', 'stocks']],
meta=[['general', 'tradeid'], ['general', 'trade_version']], errors='raise'
meta=[['general', 'tradeid'], ['general', 'trade_version']],
errors='raise'
)


Expand Down

0 comments on commit 3c94206

Please sign in to comment.