Skip to content

Commit 3b4aec2

Browse files
STYLE: Fix incorrect path to ujson directory (#39352)
1 parent 2c4c9f3 commit 3b4aec2

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
6464
# this particular codebase (e.g. src/headers, src/klib). However,
6565
# we can lint all header files since they aren't "generated" like C files are.
6666
MSG='Linting .c and .h' ; echo $MSG
67-
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp
67+
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp
6868
RET=$(($RET + $?)) ; echo $MSG "DONE"
6969

7070
fi

pandas/_libs/src/ujson/lib/ultrajsonenc.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,19 @@ INLINE_PREFIX void FASTCALL_MSVC strreverse(char *begin,
728728
while (end > begin) aux = *end, *end-- = *begin, *begin++ = aux;
729729
}
730730

731-
void Buffer_AppendIndentNewlineUnchecked(JSONObjectEncoder *enc)
732-
{
731+
void Buffer_AppendIndentNewlineUnchecked(JSONObjectEncoder *enc) {
733732
if (enc->indent > 0) Buffer_AppendCharUnchecked(enc, '\n');
734733
}
735734

736735
// This function could be refactored to only accept enc as an argument,
737736
// but this is a straight vendor from ujson source
738-
void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value)
739-
{
737+
void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value) {
740738
int i;
741-
if (enc->indent > 0)
739+
if (enc->indent > 0) {
742740
while (value-- > 0)
743741
for (i = 0; i < enc->indent; i++)
744742
Buffer_AppendCharUnchecked(enc, ' ');
743+
}
745744
}
746745

747746
void Buffer_AppendIntUnchecked(JSONObjectEncoder *enc, JSINT32 value) {
@@ -976,28 +975,28 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
976975
enc->iterBegin(obj, &tc);
977976

978977
Buffer_AppendCharUnchecked(enc, '[');
979-
Buffer_AppendIndentNewlineUnchecked (enc);
978+
Buffer_AppendIndentNewlineUnchecked(enc);
980979

981980
while (enc->iterNext(obj, &tc)) {
982981
if (count > 0) {
983982
Buffer_AppendCharUnchecked(enc, ',');
984983
#ifndef JSON_NO_EXTRA_WHITESPACE
985984
Buffer_AppendCharUnchecked(buffer, ' ');
986985
#endif
987-
Buffer_AppendIndentNewlineUnchecked (enc);
986+
Buffer_AppendIndentNewlineUnchecked(enc);
988987
}
989988

990989
iterObj = enc->iterGetValue(obj, &tc);
991990

992991
enc->level++;
993-
Buffer_AppendIndentUnchecked (enc, enc->level);
992+
Buffer_AppendIndentUnchecked(enc, enc->level);
994993
encode(iterObj, enc, NULL, 0);
995994
count++;
996995
}
997996

998997
enc->iterEnd(obj, &tc);
999-
Buffer_AppendIndentNewlineUnchecked (enc);
1000-
Buffer_AppendIndentUnchecked (enc, enc->level);
998+
Buffer_AppendIndentNewlineUnchecked(enc);
999+
Buffer_AppendIndentUnchecked(enc, enc->level);
10011000
Buffer_AppendCharUnchecked(enc, ']');
10021001
break;
10031002
}
@@ -1007,29 +1006,29 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
10071006
enc->iterBegin(obj, &tc);
10081007

10091008
Buffer_AppendCharUnchecked(enc, '{');
1010-
Buffer_AppendIndentNewlineUnchecked (enc);
1009+
Buffer_AppendIndentNewlineUnchecked(enc);
10111010

10121011
while (enc->iterNext(obj, &tc)) {
10131012
if (count > 0) {
10141013
Buffer_AppendCharUnchecked(enc, ',');
10151014
#ifndef JSON_NO_EXTRA_WHITESPACE
10161015
Buffer_AppendCharUnchecked(enc, ' ');
10171016
#endif
1018-
Buffer_AppendIndentNewlineUnchecked (enc);
1017+
Buffer_AppendIndentNewlineUnchecked(enc);
10191018
}
10201019

10211020
iterObj = enc->iterGetValue(obj, &tc);
10221021
objName = enc->iterGetName(obj, &tc, &szlen);
10231022

10241023
enc->level++;
1025-
Buffer_AppendIndentUnchecked (enc, enc->level);
1024+
Buffer_AppendIndentUnchecked(enc, enc->level);
10261025
encode(iterObj, enc, objName, szlen);
10271026
count++;
10281027
}
10291028

10301029
enc->iterEnd(obj, &tc);
1031-
Buffer_AppendIndentNewlineUnchecked (enc);
1032-
Buffer_AppendIndentUnchecked (enc, enc->level);
1030+
Buffer_AppendIndentNewlineUnchecked(enc);
1031+
Buffer_AppendIndentUnchecked(enc, enc->level);
10331032
Buffer_AppendCharUnchecked(enc, '}');
10341033
break;
10351034
}
@@ -1134,7 +1133,6 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
11341133
}
11351134

11361135
break;
1137-
11381136
}
11391137
}
11401138

pandas/_libs/src/ujson/python/date_conversions.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
Copyright (c) 2020, PyData Development Team
3+
All rights reserved.
4+
Distributed under the terms of the BSD Simplified License.
5+
The full license is in the LICENSE file, distributed with this software.
6+
*/
7+
18
// Conversion routines that are useful for serialization,
29
// but which don't interact with JSON objects directly
310

@@ -108,8 +115,8 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) {
108115
PyErr_SetString(PyExc_ValueError,
109116
"Could not convert PyDateTime to numpy datetime");
110117
}
111-
// TODO: is setting errMsg required?
112-
//((JSONObjectEncoder *)tc->encoder)->errorMsg = "";
118+
// TODO(username): is setting errMsg required?
119+
// ((JSONObjectEncoder *)tc->encoder)->errorMsg = "";
113120
// return NULL;
114121
}
115122

pandas/_libs/src/ujson/python/date_conversions.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
#ifndef PANDAS__LIBS_SRC_UJSON_DATE_CONVERSIONS
2-
#define PANDAS__LIBS_SRC_UJSON_DATE_CONVERSIONS
1+
/*
2+
Copyright (c) 2020, PyData Development Team
3+
All rights reserved.
4+
Distributed under the terms of the BSD Simplified License.
5+
The full license is in the LICENSE file, distributed with this software.
6+
*/
7+
8+
#ifndef PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_
9+
#define PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_
310

411
#define PY_SSIZE_T_CLEAN
512
#include <Python.h>
@@ -14,8 +21,8 @@ int scaleNanosecToUnit(npy_int64 *value, NPY_DATETIMEUNIT unit);
1421
// len is mutated to save the length of the returned string
1522
char *int64ToIso(int64_t value, NPY_DATETIMEUNIT base, size_t *len);
1623

17-
// TODO: this function doesn't do a lot; should augment or replace with
18-
// scaleNanosecToUnit
24+
// TODO(username): this function doesn't do a lot; should augment or
25+
// replace with scaleNanosecToUnit
1926
npy_datetime NpyDateTimeToEpoch(npy_datetime dt, NPY_DATETIMEUNIT base);
2027

2128
// Converts a Python object representing a Date / Datetime to ISO format
@@ -29,4 +36,4 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base);
2936

3037
char *int64ToIsoDuration(int64_t value, size_t *len);
3138

32-
#endif
39+
#endif // PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_

pandas/_libs/src/ujson/python/objToJSON.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ typedef char *(*PFN_PyTypeToUTF8)(JSOBJ obj, JSONTypeContext *ti,
6464
typedef struct __NpyArrContext {
6565
PyObject *array;
6666
char *dataptr;
67-
int curdim; // current dimension in array's order
68-
int stridedim; // dimension we are striding over
69-
int inc; // stride dimension increment (+/- 1)
67+
int curdim; // current dimension in array's order
68+
int stridedim; // dimension we are striding over
69+
int inc; // stride dimension increment (+/- 1)
7070
npy_intp dim;
7171
npy_intp stride;
7272
npy_intp ndim;
@@ -83,8 +83,8 @@ typedef struct __PdBlockContext {
8383
int ncols;
8484
int transpose;
8585

86-
int *cindices; // frame column -> block column map
87-
NpyArrContext **npyCtxts; // NpyArrContext for each column
86+
int *cindices; // frame column -> block column map
87+
NpyArrContext **npyCtxts; // NpyArrContext for each column
8888
} PdBlockContext;
8989

9090
typedef struct __TypeContext {
@@ -346,7 +346,6 @@ static char *NpyTimeDeltaToIsoCallback(JSOBJ Py_UNUSED(unused),
346346
/* JSON callback */
347347
static char *PyDateTimeToIsoCallback(JSOBJ obj, JSONTypeContext *tc,
348348
size_t *len) {
349-
350349
if (!PyDate_Check(obj)) {
351350
PyErr_SetString(PyExc_TypeError, "Expected date object");
352351
return NULL;
@@ -1108,7 +1107,7 @@ void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
11081107
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
11091108
GET_TC(tc)->index = 0;
11101109
GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char));
1111-
enc->outputFormat = VALUES; // for contained series
1110+
enc->outputFormat = VALUES; // for contained series
11121111
if (!GET_TC(tc)->cStr) {
11131112
PyErr_NoMemory();
11141113
}
@@ -1164,7 +1163,7 @@ void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
11641163
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
11651164
GET_TC(tc)->index = 0;
11661165
GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char));
1167-
enc->outputFormat = VALUES; // for contained series & index
1166+
enc->outputFormat = VALUES; // for contained series & index
11681167
if (!GET_TC(tc)->cStr) {
11691168
PyErr_NoMemory();
11701169
}
@@ -1364,7 +1363,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
13641363
} else {
13651364
if (PyDelta_Check(item)) {
13661365
nanosecVal = total_seconds(item) *
1367-
1000000000LL; // nanoseconds per second
1366+
1000000000LL; // nanoseconds per second
13681367
} else {
13691368
// datetime.* objects don't follow above rules
13701369
nanosecVal = PyDateTimeToEpoch(item, NPY_FR_ns);
@@ -1395,13 +1394,14 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
13951394
break;
13961395
}
13971396
} else {
1398-
cLabel = PyObject_Malloc(21); // 21 chars for int64
1399-
sprintf(cLabel, "%" NPY_DATETIME_FMT,
1397+
int size_of_cLabel = 21; // 21 chars for int 64
1398+
cLabel = PyObject_Malloc(size_of_cLabel);
1399+
snprintf(cLabel, size_of_cLabel, "%" NPY_DATETIME_FMT,
14001400
NpyDateTimeToEpoch(nanosecVal, base));
14011401
len = strlen(cLabel);
14021402
}
14031403
}
1404-
} else { // Fallback to string representation
1404+
} else { // Fallback to string representation
14051405
// Replace item with the string to keep it alive.
14061406
Py_SETREF(item, PyObject_Str(item));
14071407
if (item == NULL) {
@@ -1502,7 +1502,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
15021502
if (longVal == get_nat()) {
15031503
tc->type = JT_NULL;
15041504
} else {
1505-
15061505
if (enc->datetimeIso) {
15071506
if (enc->npyType == NPY_TIMEDELTA) {
15081507
pc->PyTypeToUTF8 = NpyTimeDeltaToIsoCallback;
@@ -1521,7 +1520,8 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
15211520
}
15221521
}
15231522

1524-
// TODO: this prevents infinite loop with mixed-type DataFrames;
1523+
// TODO(username): this prevents infinite loop with
1524+
// mixed-type DataFrames;
15251525
// refactor
15261526
enc->npyCtxtPassthru = NULL;
15271527
enc->npyType = -1;
@@ -1608,7 +1608,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
16081608
if (PyObject_HasAttrString(obj, "value")) {
16091609
value = get_long_attr(obj, "value");
16101610
} else {
1611-
value = total_seconds(obj) * 1000000000LL; // nanoseconds per second
1611+
value = total_seconds(obj) * 1000000000LL; // nanoseconds per sec
16121612
}
16131613

16141614
if (value == get_nat()) {
@@ -1620,7 +1620,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
16201620
} else {
16211621
unit = ((PyObjectEncoder *)tc->encoder)->datetimeUnit;
16221622
if (scaleNanosecToUnit(&value, unit) != 0) {
1623-
// TODO: Add some kind of error handling here
1623+
// TODO(username): Add some kind of error handling here
16241624
}
16251625

16261626
exc = PyErr_Occurred();
@@ -2039,7 +2039,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
20392039
PyObject *newobj;
20402040
PyObject *oinput = NULL;
20412041
PyObject *oensureAscii = NULL;
2042-
int idoublePrecision = 10; // default double precision setting
2042+
int idoublePrecision = 10; // default double precision setting
20432043
PyObject *oencodeHTMLChars = NULL;
20442044
char *sOrient = NULL;
20452045
char *sdateFormat = NULL;
@@ -2052,7 +2052,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
20522052
Object_endTypeContext,
20532053
Object_getStringValue,
20542054
Object_getLongValue,
2055-
NULL, // getIntValue is unused
2055+
NULL, // getIntValue is unused
20562056
Object_getDoubleValue,
20572057
Object_getBigNumStringValue,
20582058
Object_iterBegin,
@@ -2064,11 +2064,11 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
20642064
PyObject_Malloc,
20652065
PyObject_Realloc,
20662066
PyObject_Free,
2067-
-1, // recursionMax
2067+
-1, // recursionMax
20682068
idoublePrecision,
2069-
1, // forceAscii
2070-
0, // encodeHTMLChars
2071-
0, // indent
2069+
1, // forceAscii
2070+
0, // encodeHTMLChars
2071+
0, // indent
20722072
}};
20732073
JSONObjectEncoder *encoder = (JSONObjectEncoder *)&pyEncoder;
20742074

pandas/_libs/src/ujson/python/ujson.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ static PyModuleDef moduledef = {
7373

7474

7575
PyMODINIT_FUNC PyInit_json(void) {
76-
initObjToJSON(); // TODO: clean up, maybe via tp_free?
76+
initObjToJSON(); // TODO(username): clean up, maybe via tp_free?
7777
return PyModuleDef_Init(&moduledef);
78-
7978
}

0 commit comments

Comments
 (0)