Skip to content

Commit 06d48d0

Browse files
harisbalharisbal
authored and
harisbal
committed
Update docstring _restore_dropped_levels_multijoin
2 parents e10cbde + b9fc22d commit 06d48d0

34 files changed

+662
-119
lines changed

ci/code_checks.sh

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
4444
flake8 pandas/_libs --filename=*.pxi.in,*.pxd --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
4545
RET=$(($RET + $?)) ; echo $MSG "DONE"
4646

47+
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
48+
# it doesn't make a difference, but we want to be internally consistent.
49+
# Note: this grep pattern is (intended to be) equivalent to the python
50+
# regex r'(?<![ ->])> '
51+
MSG='Linting .pyx code for spacing conventions in casting' ; echo $MSG
52+
! grep -r -E --include '*.pyx' --include '*.pxi.in' '> ' pandas/_libs | grep -v '[ ->]> '
53+
RET=$(($RET + $?)) ; echo $MSG "DONE"
54+
4755
# readability/casting: Warnings about C casting instead of C++ casting
4856
# runtime/int: Warnings about using C number types instead of C++ ones
4957
# build/include_subdir: Warnings about prefacing included header files with directory

doc/source/contributing.rst

+52
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,54 @@ Alternatively, you can install the ``grep`` and ``xargs`` commands via the
612612
`MinGW <http://www.mingw.org/>`__ toolchain, and it will allow you to run the
613613
commands above.
614614

615+
.. _contributing.import-formatting:
616+
617+
Import Formatting
618+
~~~~~~~~~~~~~~~~~
619+
*pandas* uses `isort <https://pypi.org/project/isort/>`__ to standardise import
620+
formatting across the codebase.
621+
622+
A guide to import layout as per pep8 can be found `here <https://www.python.org/dev/peps/pep-0008/#imports/>`__.
623+
624+
A summary of our current import sections ( in order ):
625+
626+
* Future
627+
* Python Standard Library
628+
* Third Party
629+
* ``pandas._libs``, ``pandas.compat``, ``pandas.util._*``, ``pandas.errors`` (largely not dependent on ``pandas.core``)
630+
* ``pandas.core.dtypes`` (largely not dependent on the rest of ``pandas.core``)
631+
* Rest of ``pandas.core.*``
632+
* Non-core ``pandas.io``, ``pandas.plotting``, ``pandas.tseries``
633+
* Local application/library specific imports
634+
635+
Imports are alphabetically sorted within these sections.
636+
637+
638+
As part of :ref:`Continuous Integration <contributing.ci>` checks we run::
639+
640+
isort --recursive --check-only pandas
641+
642+
to check that imports are correctly formatted as per the `setup.cfg`.
643+
644+
If you see output like the below in :ref:`Continuous Integration <contributing.ci>` checks:
645+
646+
.. code-block:: shell
647+
648+
Check import format using isort
649+
ERROR: /home/travis/build/pandas-dev/pandas/pandas/io/pytables.py Imports are incorrectly sorted
650+
Check import format using isort DONE
651+
The command "ci/code_checks.sh" exited with 1
652+
653+
You should run::
654+
655+
isort pandas/io/pytables.py
656+
657+
to automatically format imports correctly. This will modify your local copy of the files.
658+
659+
The `--recursive` flag can be passed to sort all files in a directory.
660+
661+
You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.
662+
615663
Backwards Compatibility
616664
~~~~~~~~~~~~~~~~~~~~~~~
617665

@@ -1078,6 +1126,8 @@ or a new keyword argument (`example <https://github.com/pandas-dev/pandas/blob/v
10781126
Contributing your changes to *pandas*
10791127
=====================================
10801128

1129+
.. _contributing.commit-code:
1130+
10811131
Committing your code
10821132
--------------------
10831133

@@ -1122,6 +1172,8 @@ Now you can commit your changes in your local repository::
11221172

11231173
git commit -m
11241174

1175+
.. _contributing.push-code:
1176+
11251177
Pushing your changes
11261178
--------------------
11271179

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ Timezones
11911191
- Bug in :meth:`DatetimeIndex.unique` that did not re-localize tz-aware dates correctly (:issue:`21737`)
11921192
- Bug when indexing a :class:`Series` with a DST transition (:issue:`21846`)
11931193
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` where an ``AmbiguousTimeError`` or ``NonExistentTimeError`` would raise if a timezone aware timeseries ended on a DST transition (:issue:`19375`, :issue:`10117`)
1194+
- Bug in :meth:`DataFrame.drop` and :meth:`Series.drop` when specifying a tz-aware Timestamp key to drop from a :class:`DatetimeIndex` with a DST transition (:issue:`21761`)
11941195

11951196
Offsets
11961197
^^^^^^^

pandas/_libs/algos.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import missing
3232

3333
cdef float64_t FP_ERR = 1e-13
3434

35-
cdef double NaN = <double> np.NaN
35+
cdef double NaN = <double>np.NaN
3636
cdef double nan = NaN
3737

3838
cdef int64_t iNaT = get_nat()
@@ -242,7 +242,7 @@ def nancorr(ndarray[float64_t, ndim=2] mat, bint cov=0, minp=None):
242242
int64_t nobs = 0
243243
float64_t vx, vy, sumx, sumy, sumxx, sumyy, meanx, meany, divisor
244244

245-
N, K = (<object> mat).shape
245+
N, K = (<object>mat).shape
246246

247247
if minp is None:
248248
minpv = 1
@@ -307,7 +307,7 @@ def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1):
307307
int64_t nobs = 0
308308
float64_t vx, vy, sumx, sumxx, sumyy, mean, divisor
309309

310-
N, K = (<object> mat).shape
310+
N, K = (<object>mat).shape
311311

312312
result = np.empty((K, K), dtype=np.float64)
313313
mask = np.isfinite(mat).view(np.uint8)
@@ -531,7 +531,7 @@ def pad_2d_inplace(ndarray[algos_t, ndim=2] values,
531531
algos_t val
532532
int lim, fill_count = 0
533533

534-
K, N = (<object> values).shape
534+
K, N = (<object>values).shape
535535

536536
# GH#2778
537537
if N == 0:
@@ -730,7 +730,7 @@ def backfill_2d_inplace(ndarray[algos_t, ndim=2] values,
730730
algos_t val
731731
int lim, fill_count = 0
732732

733-
K, N = (<object> values).shape
733+
K, N = (<object>values).shape
734734

735735
# GH#2778
736736
if N == 0:

pandas/_libs/algos_common_helper.pxi.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def diff_2d_{{name}}(ndarray[{{c_type}}, ndim=2] arr,
3434
cdef:
3535
Py_ssize_t i, j, sx, sy
3636

37-
sx, sy = (<object> arr).shape
37+
sx, sy = (<object>arr).shape
3838
if arr.flags.f_contiguous:
3939
if axis == 0:
4040
if periods >= 0:
@@ -88,14 +88,14 @@ def put2d_{{name}}_{{dest_name}}(ndarray[{{c_type}}, ndim=2, cast=True] values,
8888
# ensure_dtype
8989
#----------------------------------------------------------------------
9090

91-
cdef int PLATFORM_INT = (<ndarray> np.arange(0, dtype=np.intp)).descr.type_num
91+
cdef int PLATFORM_INT = (<ndarray>np.arange(0, dtype=np.intp)).descr.type_num
9292

9393

9494
def ensure_platform_int(object arr):
9595
# GH3033, GH1392
9696
# platform int is the size of the int pointer, e.g. np.intp
9797
if util.is_array(arr):
98-
if (<ndarray> arr).descr.type_num == PLATFORM_INT:
98+
if (<ndarray>arr).descr.type_num == PLATFORM_INT:
9999
return arr
100100
else:
101101
return arr.astype(np.intp)
@@ -105,7 +105,7 @@ def ensure_platform_int(object arr):
105105

106106
def ensure_object(object arr):
107107
if util.is_array(arr):
108-
if (<ndarray> arr).descr.type_num == NPY_OBJECT:
108+
if (<ndarray>arr).descr.type_num == NPY_OBJECT:
109109
return arr
110110
else:
111111
return arr.astype(np.object_)
@@ -142,7 +142,7 @@ def get_dispatch(dtypes):
142142

143143
def ensure_{{name}}(object arr, copy=True):
144144
if util.is_array(arr):
145-
if (<ndarray> arr).descr.type_num == NPY_{{c_type}}:
145+
if (<ndarray>arr).descr.type_num == NPY_{{c_type}}:
146146
return arr
147147
else:
148148
return arr.astype(np.{{dtype}}, copy=copy)

pandas/_libs/algos_rank_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def rank_2d_{{dtype}}(object in_arr, axis=0, ties_method='average',
263263
np.putmask(values, mask, nan_value)
264264
{{endif}}
265265

266-
n, k = (<object> values).shape
266+
n, k = (<object>values).shape
267267
ranks = np.empty((n, k), dtype='f8')
268268

269269
{{if dtype == 'object'}}

pandas/_libs/algos_take_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ cdef _take_2d(ndarray[take_t, ndim=2] values, object idx):
278278
ndarray[take_t, ndim=2] result
279279
object val
280280

281-
N, K = (<object> values).shape
281+
N, K = (<object>values).shape
282282

283283
if take_t is object:
284284
# evaluated at compile-time

pandas/_libs/groupby.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from algos import take_2d_axis1_float64_float64, groupsort_indexer, tiebreakers
2222

2323
cdef int64_t iNaT = get_nat()
2424

25-
cdef double NaN = <double> np.NaN
25+
cdef double NaN = <double>np.NaN
2626
cdef double nan = NaN
2727

2828

@@ -115,7 +115,7 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
115115
assert min_count == -1, "'min_count' only used in add and prod"
116116

117117
ngroups = len(counts)
118-
N, K = (<object> values).shape
118+
N, K = (<object>values).shape
119119

120120
indexer, _counts = groupsort_indexer(labels, ngroups)
121121
counts[:] = _counts[1:]
@@ -152,7 +152,7 @@ def group_cumprod_float64(float64_t[:, :] out,
152152
float64_t[:, :] accum
153153
int64_t lab
154154

155-
N, K = (<object> values).shape
155+
N, K = (<object>values).shape
156156
accum = np.ones_like(values)
157157

158158
with nogil:
@@ -189,7 +189,7 @@ def group_cumsum(numeric[:, :] out,
189189
numeric[:, :] accum
190190
int64_t lab
191191

192-
N, K = (<object> values).shape
192+
N, K = (<object>values).shape
193193
accum = np.zeros_like(values)
194194

195195
with nogil:
@@ -226,7 +226,7 @@ def group_shift_indexer(ndarray[int64_t] out, ndarray[int64_t] labels,
226226
int64_t[:] label_seen = np.zeros(ngroups, dtype=np.int64)
227227
int64_t[:, :] label_indexer
228228

229-
N, = (<object> labels).shape
229+
N, = (<object>labels).shape
230230

231231
if periods < 0:
232232
periods = -periods

pandas/_libs/groupby_helper.pxi.in

+16-16
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def group_add_{{name}}(ndarray[{{c_type}}, ndim=2] out,
4848
nobs = np.zeros_like(out)
4949
sumx = np.zeros_like(out)
5050

51-
N, K = (<object> values).shape
51+
N, K = (<object>values).shape
5252

5353
with nogil:
5454

@@ -95,7 +95,7 @@ def group_prod_{{name}}(ndarray[{{c_type}}, ndim=2] out,
9595
nobs = np.zeros_like(out)
9696
prodx = np.ones_like(out)
9797

98-
N, K = (<object> values).shape
98+
N, K = (<object>values).shape
9999

100100
with nogil:
101101
for i in range(N):
@@ -141,7 +141,7 @@ def group_var_{{name}}(ndarray[{{c_type}}, ndim=2] out,
141141
nobs = np.zeros_like(out)
142142
mean = np.zeros_like(out)
143143

144-
N, K = (<object> values).shape
144+
N, K = (<object>values).shape
145145

146146
out[:, :] = 0.0
147147

@@ -193,7 +193,7 @@ def group_mean_{{name}}(ndarray[{{c_type}}, ndim=2] out,
193193
nobs = np.zeros_like(out)
194194
sumx = np.zeros_like(out)
195195

196-
N, K = (<object> values).shape
196+
N, K = (<object>values).shape
197197

198198
with nogil:
199199
for i in range(N):
@@ -238,7 +238,7 @@ def group_ohlc_{{name}}(ndarray[{{c_type}}, ndim=2] out,
238238
if len(labels) == 0:
239239
return
240240

241-
N, K = (<object> values).shape
241+
N, K = (<object>values).shape
242242

243243
if out.shape[1] != 4:
244244
raise ValueError('Output array must have 4 columns')
@@ -312,14 +312,14 @@ def group_last_{{name}}(ndarray[{{c_type}}, ndim=2] out,
312312
if not len(values) == len(labels):
313313
raise AssertionError("len(index) != len(labels)")
314314

315-
nobs = np.zeros((<object> out).shape, dtype=np.int64)
315+
nobs = np.zeros((<object>out).shape, dtype=np.int64)
316316
{{if name == 'object'}}
317-
resx = np.empty((<object> out).shape, dtype=object)
317+
resx = np.empty((<object>out).shape, dtype=object)
318318
{{else}}
319319
resx = np.empty_like(out)
320320
{{endif}}
321321

322-
N, K = (<object> values).shape
322+
N, K = (<object>values).shape
323323

324324
{{if name == "object"}}
325325
if True: # make templating happy
@@ -369,14 +369,14 @@ def group_nth_{{name}}(ndarray[{{c_type}}, ndim=2] out,
369369
if not len(values) == len(labels):
370370
raise AssertionError("len(index) != len(labels)")
371371

372-
nobs = np.zeros((<object> out).shape, dtype=np.int64)
372+
nobs = np.zeros((<object>out).shape, dtype=np.int64)
373373
{{if name=='object'}}
374-
resx = np.empty((<object> out).shape, dtype=object)
374+
resx = np.empty((<object>out).shape, dtype=object)
375375
{{else}}
376376
resx = np.empty_like(out)
377377
{{endif}}
378378

379-
N, K = (<object> values).shape
379+
N, K = (<object>values).shape
380380

381381
{{if name == "object"}}
382382
if True: # make templating happy
@@ -462,7 +462,7 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
462462

463463
tiebreak = tiebreakers[ties_method]
464464
keep_na = na_option == 'keep'
465-
N, K = (<object> values).shape
465+
N, K = (<object>values).shape
466466
grp_sizes = np.ones_like(out)
467467

468468
# Copy values into new array in order to fill missing data
@@ -635,7 +635,7 @@ def group_max(ndarray[groupby_t, ndim=2] out,
635635
maxx.fill(-np.inf)
636636
nan_val = NAN
637637

638-
N, K = (<object> values).shape
638+
N, K = (<object>values).shape
639639

640640
with nogil:
641641
for i in range(N):
@@ -697,7 +697,7 @@ def group_min(ndarray[groupby_t, ndim=2] out,
697697
minx.fill(np.inf)
698698
nan_val = NAN
699699

700-
N, K = (<object> values).shape
700+
N, K = (<object>values).shape
701701

702702
with nogil:
703703
for i in range(N):
@@ -744,7 +744,7 @@ def group_cummin(ndarray[groupby_t, ndim=2] out,
744744
ndarray[groupby_t, ndim=2] accum
745745
int64_t lab
746746

747-
N, K = (<object> values).shape
747+
N, K = (<object>values).shape
748748
accum = np.empty_like(values)
749749
if groupby_t is int64_t:
750750
accum.fill(_int64_max)
@@ -792,7 +792,7 @@ def group_cummax(ndarray[groupby_t, ndim=2] out,
792792
ndarray[groupby_t, ndim=2] accum
793793
int64_t lab
794794

795-
N, K = (<object> values).shape
795+
N, K = (<object>values).shape
796796
accum = np.empty_like(values)
797797
if groupby_t is int64_t:
798798
accum.fill(-_int64_max)

pandas/_libs/hashtable_class_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ cdef class {{name}}HashTable(HashTable):
318318
for i in range(n):
319319
key = keys[i]
320320
k = kh_put_{{dtype}}(self.table, key, &ret)
321-
self.table.vals[k] = <Py_ssize_t> values[i]
321+
self.table.vals[k] = <Py_ssize_t>values[i]
322322

323323
@cython.boundscheck(False)
324324
def map_locations(self, ndarray[{{dtype}}_t, ndim=1] values):

pandas/_libs/join.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from numpy cimport (ndarray,
1111
cnp.import_array()
1212

1313

14-
cdef double NaN = <double> np.NaN
14+
cdef double NaN = <double>np.NaN
1515
cdef double nan = NaN
1616

1717
from pandas._libs.algos import groupsort_indexer, ensure_platform_int

0 commit comments

Comments
 (0)